Skip to content

Auto zoom when adding a layer from the UI#1286

Merged
martinRenou merged 5 commits intogeojupyter:mainfrom
nakul-py:autoZoom
Apr 16, 2026
Merged

Auto zoom when adding a layer from the UI#1286
martinRenou merged 5 commits intogeojupyter:mainfrom
nakul-py:autoZoom

Conversation

@nakul-py
Copy link
Copy Markdown
Member

@nakul-py nakul-py commented Apr 9, 2026

Description

Auto zoom to layer's extent when adding a layer from the UI.

Also now in collaboration only zooms for whom, who created the layer, Not for all collaborators.
Respects the user view 👍

zoom-collab.mp4

Checklist

  • PR has a descriptive title and content.
  • PR description contains references to any issues the PR resolves, e.g. Resolves #XXX.
  • PR has one of the labels: documentation, bug, enhancement, feature, maintenance
  • Checks are passing.
    Failing lint checks can be resolved with:
    • pre-commit run --all-files
    • jlpm run lint
  • If you wish to be cited for your contribution, CITATION.cff contains an author entry for yourself

📚 Documentation preview: https://jupytergis--1286.org.readthedocs.build/en/1286/
💡 JupyterLite preview: https://jupytergis--1286.org.readthedocs.build/en/1286/lite
💡 Specta preview: https://jupytergis--1286.org.readthedocs.build/en/1286/lite/specta

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Binder 👈 Launch a Binder on branch nakul-py/jupytergis/autoZoom

@nakul-py nakul-py added the enhancement New feature or request label Apr 9, 2026
@nakul-py nakul-py requested a review from martinRenou April 9, 2026 11:46
@martinRenou
Copy link
Copy Markdown
Member

That's really cool thanks!

This PR is fixing #667

Screencast.From.2026-04-09.14-11-26.mp4

Copy link
Copy Markdown
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I badly want to merge this PR, but I don't think we can as it is... The issue is that when collaboratively annotating a map with markers we'll have the view keep on jumping whenever someone else is adding a new annotation.

We need to think of a way to track the origin of the change, and only zoom to the layer if it was created by the current user. I guess we have no way of knowing that though... Thoughts @gjmooney @davidbrochart @trungleduc ?

@martinRenou
Copy link
Copy Markdown
Member

We could introduce in our document model an "origin" attribute for Layers, that's a UUID generated by the front-end.

If the origin of the layer is the same as the current page, we do zoom.

I wonder if the added "noise" in the document would make it annoying or if it would be just fine.

@gjmooney
Copy link
Copy Markdown
Collaborator

gjmooney commented Apr 9, 2026

Doesn't the awareness stuff have a unique identifier? Could we use that as the origin?Alternatively, we could disable the zoom if there's other collaborators connected?

@martinRenou
Copy link
Copy Markdown
Member

Alternatively, we could disable the zoom if there's other collaborators connected?

Probably that's a good degraded solution for now indeed 👍🏽 then we don't mess around with the document model (yet?).

If we really want that in the multi-collaborators case we can rethink this later.

@mfisher87
Copy link
Copy Markdown
Member

Couldn't this be an event in the awareness, but not the document, like cursor moves? I feel like I'm missing something important here!

@martinRenou
Copy link
Copy Markdown
Member

Couldn't this be an event in the awareness

Indeed I guess we could explore having a new entry in the awareness, last_created_layer?
Then we can maybe try to react on it being changed for the current user view?

If we take this approach, we need to hack around the awareness when it comes from Python.

Can you maybe test this approach @nakul-py ?

@mfisher87
Copy link
Copy Markdown
Member

mfisher87 commented Apr 10, 2026

If we take this approach, we need to hack around the awareness when it comes from Python.

Not sure what you mean by "hack" here, but to me the least hacky way to do this would be to specify the source of the event -- was it triggered by an LLM, by programmatic API call, or by user interaction?

e.g. lastCreatedLayer: {id: "...", source: "PythonAPI", userId: "..."}?

I know very little about this part of JupyterGIS and I'd like to learn more about it and see and touch it. Maybe we could have a session to pair/group program on it some time?

@nakul-py nakul-py requested a review from martinRenou April 13, 2026 14:38
Comment on lines 582 to +594
syncSelected(value: { [key: string]: ISelection }, emitter?: string): void {
this.sharedModel.awareness.setLocalStateField('selected', {
value,
emitter,
});
}

syncLastAddedLayer(layerId: string): void {
this.sharedModel.awareness.setLocalStateField('lastAddedLayer', {
layerId,
clientId: this.getClientId(),
});
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check why we don't need to inject clientId for syncSelected but we do for "lastAddedLayer"? Since the selection is bound to the current user I assume it's bound to the clientId somehow too. So you probably don't need to add clientId here. To be confirmed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK let me check this one 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can get rid of manually adding clientId and getting it from awareness.

Comment thread packages/schema/src/doc.ts
@martinRenou
Copy link
Copy Markdown
Member

This is looking nice!

Although for the Python API it does not work how we want:

Screencast.From.2026-04-14.10-55-08.mp4

If we take this approach, we need to hack around the awareness when it comes from Python.

Not sure what you mean by "hack" here, but to me the least hacky way to do this would be to specify the source of the event

Now, that is what I meant. The Python API does not write into the awareness so we'll need to have a special case for this one.

@martinRenou martinRenou self-assigned this Apr 16, 2026
Copy link
Copy Markdown
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Let's get this one in and figure out the Python case separately. #1246 will probably help us, or at least be a good step in the direction we want.

@martinRenou martinRenou merged commit 8152da7 into geojupyter:main Apr 16, 2026
16 checks passed
@nakul-py nakul-py deleted the autoZoom branch April 16, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zoom to data layer when calling explore(data)

4 participants