Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions packages/base/src/mainview/mainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,34 +435,43 @@ export class MainView extends React.Component<IMainViewProps, IStates> {

const view = this._Map.getView();

view.on('change:center', () => this._updateCenter());

// TODO: Note for the future, will need to update listeners if view changes
view.on(
'change:center',
throttle(() => {
// Not syncing center if following someone else
if (this._model.localState?.remoteUser) {
return;
}
const view = this._Map.getView();
const center = view.getCenter();
const zoom = view.getZoom();
if (!center || !zoom) {
return;
}
this._model.syncViewport(
{
coordinates: {
x: center[0],
y: center[1],
},
zoom,
const syncViewportThrottled = throttle(() => {
// Not syncing center if following someone else
if (this._model.localState?.remoteUser) {
return;
}

const view = this._Map.getView();
const center = view.getCenter();
const zoom = view.getZoom();

if (!center || !zoom) {
return;
}

const currentExtent = view.calculateExtent(this._Map.getSize());
this._model.syncViewport(
{
coordinates: {
x: center[0],
y: center[1],
},
this._mainViewModel.id,
);
}),
);
zoom,
extent: [
currentExtent[0],
currentExtent[1],
currentExtent[2],
currentExtent[3],
],
},
this._mainViewModel.id,
);
}, 200);

view.on('change:center', () => {
this._updateCenter();
syncViewportThrottled();
});

this._Map.on('postrender', () => {
if (this.state.annotations) {
Expand Down
1 change: 1 addition & 0 deletions packages/schema/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type JgisCoordinates = { x: number; y: number };
export interface IViewPortState {
coordinates: JgisCoordinates;
zoom: number;
extent: [number, number, number, number];
}

export type Pointer = {
Expand Down
6 changes: 6 additions & 0 deletions python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class GISDocument(CommWidget):
Create a new GISDocument object.

:param path: the path to the file that you would like to open. If not provided, a new ephemeral widget will be created.

Collaborative client state from the front end is mirrored into :mod:`ypywidgets`
``Awareness`` on the kernel. Subscribe with ``on_awareness_change(callback)``
(returns a subscription id; use ``unobserve_awareness(id)`` to remove). The
current snapshot is available as ``awareness.states`` on the underlying
``pycrdt.Awareness`` via the inherited ``awareness`` property.
"""

def __init__(
Expand Down
4 changes: 4 additions & 0 deletions python/jupytergis_lab/src/notebookrenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const CLASS_NAME = 'jupytergis-notebook-widget';

export class YJupyterGISModel extends JupyterYModel {
jupyterGISModel: JupyterGISModel;

get awareness() {
return this.jupyterGISModel?.sharedModel?.awareness;
}
}

export class YJupyterGISLuminoWidget extends Panel {
Expand Down
Loading