import solara
import ipyleaflet
from solara import reactive
from components import LayersControlPrototype
LOCAL_TILE_SERVER_URL = "http://localhost:5000/{path}"
XYZ_URL = LOCAL_TILE_SERVER_URL.format(path="{z}/{x}/{y}")
ndvi_url = f"{XYZ_URL}?url=/data/ndvi.tif&colormap=ylgnbu&vmin=0&vmax=1"
false_url = f"{XYZ_URL}?url=/data/hyperspectral1.tif&b=27&b=20&b=11&vmin=1460&vmin=1427&vmin=1131&vmax=2898&vmax=3510&vmax=2475"
natural_url = f"{XYZ_URL}?url=/data/hyperspectral1.tif&b=16&b=10&b=7&vmin=790&vmin=855&vmin=634&vmax=4178&vmax=2912&vmax=2197"
layer_defs = {
'Natural': dict(
visible = reactive(True),
opacity = reactive(1.0),
url = natural_url,
),
'False color': dict(
visible = reactive(True),
opacity = reactive(1.0),
url = false_url,
removable = True, # Allow this layer to be removed
),
'NDVI': dict(
visible = reactive(True),
opacity = reactive(1.0),
url = ndvi_url,
removable = True, # Allow this layer to be removed
),
}
layer_names = reactive([key for key in layer_defs])
meta_layer_defs = reactive(layer_defs)
center = solara.reactive((30,38))
zoom = solara.reactive(12)
@solara.component
def Page():
layers_to_add = {key:layer_defs[key] for key in layer_names.value}
layers = [
ipyleaflet.TileLayer.element(
url = layer['url'], # 👀 In this notebook we defined url directly,
# NOT as a reactive variable.
opacity = layer['opacity'].value,
visible = layer['visible'].value,
)
for _,layer in layers_to_add.items()
]
with solara.Columns([1,2]):
LayersControlPrototype(
layers_to_add,
layer_names = layer_names,
meta=meta_layer_defs
)
ipyleaflet.Map.element(
scroll_wheel_zoom = True,
zoom = zoom.value,
on_zoom = zoom.set,
center = center.value,
on_center = center.set,
layers = layers,
controls = []
)
Page()