Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add on_zoom #1214

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions python/ipyleaflet/ipyleaflet/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3171,14 +3171,20 @@ def substitute(self, old, new):

# Event handling
_interaction_callbacks = Instance(CallbackDispatcher, ())
_zoom_callbacks = Instance(CallbackDispatcher, ())

def _handle_leaflet_event(self, _, content, buffers):
if content.get("event", "") == "interaction":
self._interaction_callbacks(**content)
if content.get("event", "") == "zoom":
self._zoom_callbacks(**content)

def on_interaction(self, callback, remove=False):
self._interaction_callbacks.register_callback(callback, remove=remove)

def on_zoom(self, callback, remove=False):
self._zoom_callbacks.register_callback(callback, remove=remove)

def fit_bounds(self, bounds):
"""Sets a map view that contains the given geographical bounds
with the maximum zoom level possible.
Expand Down
4 changes: 4 additions & 0 deletions python/jupyter_leaflet/src/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ export class LeafletMapView extends LeafletDOMWidgetView {
const z = e.target.getZoom();
this.model.set('zoom', z);
this.dirty = false;
this.send({
event: 'zoom',
zoom: z,
});
}
this.model.update_bounds().then(() => {
this.touch();
Expand Down
Loading