From 084349a04797db2d3f4527b9fa3c57e07008a557 Mon Sep 17 00:00:00 2001 From: Oliver Lopez Date: Wed, 3 Jul 2024 20:41:01 -0700 Subject: [PATCH] Add on_zoom --- python/ipyleaflet/ipyleaflet/leaflet.py | 6 ++++++ python/jupyter_leaflet/src/Map.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/python/ipyleaflet/ipyleaflet/leaflet.py b/python/ipyleaflet/ipyleaflet/leaflet.py index f68039dc..265d5e56 100644 --- a/python/ipyleaflet/ipyleaflet/leaflet.py +++ b/python/ipyleaflet/ipyleaflet/leaflet.py @@ -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. diff --git a/python/jupyter_leaflet/src/Map.ts b/python/jupyter_leaflet/src/Map.ts index b68fd7de..3937d8ec 100644 --- a/python/jupyter_leaflet/src/Map.ts +++ b/python/jupyter_leaflet/src/Map.ts @@ -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();