Spaces:
Sleeping
Sleeping
Add demo app
Browse files- pages/demo.py +39 -0
pages/demo.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
# ipyleaflet
|
3 |
+
Map visualization using [ipyleaflet](https://ipyleaflet.readthedocs.io/), a ipywidgets wrapper for [leaflet.js](https://leafletjs.com/)
|
4 |
+
"""
|
5 |
+
import leafmap
|
6 |
+
import ipyleaflet
|
7 |
+
import solara
|
8 |
+
import ipywidgets as widgets
|
9 |
+
|
10 |
+
# zoom = solara.reactive(4)
|
11 |
+
# center = solara.reactive((40, -100))
|
12 |
+
|
13 |
+
class Map(leafmap.Map):
|
14 |
+
def __init__(self, **kwargs):
|
15 |
+
super().__init__(**kwargs)
|
16 |
+
# Add what you want below
|
17 |
+
self.add_basemap("OpenTopoMap")
|
18 |
+
|
19 |
+
self.add_basemap("Esri.NatGeoWorldMap")
|
20 |
+
|
21 |
+
button = widgets.Button(description="Add Marker")
|
22 |
+
control = ipyleaflet.WidgetControl(widget=button, position="topright")
|
23 |
+
self.add_control(control)
|
24 |
+
|
25 |
+
|
26 |
+
@solara.component
|
27 |
+
def Page():
|
28 |
+
with solara.Column(style={"min-width": "500px", "height": "500px"}):
|
29 |
+
# solara components support reactive variables
|
30 |
+
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
31 |
+
# using 3rd party widget library require wiring up the events manually
|
32 |
+
# using zoom.value and zoom.set
|
33 |
+
Map.element( # type: ignore
|
34 |
+
zoom=4,
|
35 |
+
center=[40, -100],
|
36 |
+
scroll_wheel_zoom=True,
|
37 |
+
)
|
38 |
+
# solara.Text(f"Zoom: {zoom.value}")
|
39 |
+
# solara.Text(f"Center: {center.value}")
|