"""
Try adding layers (and then removing them):
e.g.,
https://tile.openstreetmap.org/{z}/{x}/{y}.png
https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png
"""
import solara
import ipyleaflet
from components import LayersControlMockup
import ipyleaflet
center = solara.reactive((0,0))
zoom = solara.reactive(5)
meta_layer_names = solara.reactive([])
meta_layer_defs = solara.reactive({})
@solara.component
def Page():
layers_to_add = {key: meta_layer_defs.value[key]
for key in meta_layer_names.value if key in meta_layer_defs.value}
layers = [
ipyleaflet.TileLayer.element(
url = layer['url'].value if hasattr(layer['url'],'value') else layer['url'],
opacity = layer['opacity'].value,
visible = layer['visible'].value,
)
for _,layer in layers_to_add.items()
]
with solara.Columns([1,2]):
LayersControlMockup(
layers_to_add,
layer_names = meta_layer_names,
meta_layers=meta_layer_defs,
)
# 👀 We need to wrap the Map in a Column with
# isolation:isolate
# see: https://developer.mozilla.org/en-US/docs/Web/CSS/isolation
# to prevent the TileLayers from interfering with the global
# z-index stacking of the modal.
with solara.Column(style={"isolation": "isolate"}):
ipyleaflet.Map.element(
scroll_wheel_zoom = True,
zoom = zoom.value,
on_zoom = zoom.set,
center = center.value,
on_center = center.set,
layers = layers,
)