Bläddra i källkod

fix async leaflet demo

Falko Schindler 5 månader sedan
förälder
incheckning
d72bac2724
1 ändrade filer med 13 tillägg och 10 borttagningar
  1. 13 10
      website/documentation/content/leaflet_documentation.py

+ 13 - 10
website/documentation/content/leaflet_documentation.py

@@ -182,15 +182,18 @@ def run_layer_methods() -> None:
     This is necessary when you want to run methods like fitting the bounds of the map right after the map is created.
     This is necessary when you want to run methods like fitting the bounds of the map right after the map is created.
 ''')
 ''')
 async def wait_for_init() -> None:
 async def wait_for_init() -> None:
-    m = ui.leaflet(zoom=5)
-    central_park = m.generic_layer(name='polygon', args=[[
-        (40.767809, -73.981249),
-        (40.800273, -73.958291),
-        (40.797011, -73.949683),
-        (40.764704, -73.973741),
-    ]])
-    await m.initialized()
-    bounds = await central_park.run_method('getBounds')
-    m.run_map_method('fitBounds', [[bounds['_southWest'], bounds['_northEast']]])
+    # @ui.page('/')
+    async def page():
+        m = ui.leaflet(zoom=5)
+        central_park = m.generic_layer(name='polygon', args=[[
+            (40.767809, -73.981249),
+            (40.800273, -73.958291),
+            (40.797011, -73.949683),
+            (40.764704, -73.973741),
+        ]])
+        await m.initialized()
+        bounds = await central_park.run_method('getBounds')
+        m.run_map_method('fitBounds', [[bounds['_southWest'], bounds['_northEast']]])
+    ui.timer(0, page, once=True)  # HIDE
 
 
 doc.reference(ui.leaflet)
 doc.reference(ui.leaflet)