Browse Source

add some delay to allow zoom and center to settle (#3125)

Falko Schindler 1 year ago
parent
commit
81db6d757c
2 changed files with 6 additions and 3 deletions
  1. 2 1
      nicegui/elements/leaflet.js
  2. 4 2
      nicegui/elements/leaflet.py

+ 2 - 1
nicegui/elements/leaflet.js

@@ -62,7 +62,8 @@ export default {
       "preclick",
       "zoomanim",
     ]) {
-      this.map.on(type, (e) => {
+      this.map.on(type, async (e) => {
+        await this.$nextTick(); // NOTE: allow zoom and center to both be updated
         this.$emit(`map-${type}`, {
           ...e,
           originalEvent: undefined,

+ 4 - 2
nicegui/elements/leaflet.py

@@ -82,10 +82,12 @@ class Leaflet(Element, component='leaflet.js'):
         await self.client.connected()
         await event.wait()
 
-    def _handle_moveend(self, e: GenericEventArguments) -> None:
+    async def _handle_moveend(self, e: GenericEventArguments) -> None:
+        await asyncio.sleep(0.02)  # NOTE: wait for zoom to be updated as well
         self.center = e.args['center']
 
-    def _handle_zoomend(self, e: GenericEventArguments) -> None:
+    async def _handle_zoomend(self, e: GenericEventArguments) -> None:
+        await asyncio.sleep(0.02)  # NOTE: wait for center to be updated as well
         self.zoom = e.args['zoom']
 
     def run_method(self, name: str, *args: Any, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse: