import solara
import ipyleaflet
from components import LayersControl
import json
with open('colormaps.json') as f:
available_colormaps = json.load(f)
colormaps = [key for key in available_colormaps]
bounds = [
[
29.382175075145366,
37.35351562499985
],
[
30.145127183376204,
38.759765624999844
]
]
natural_url = "http://localhost:5000/{z}/{x}/{y}?url=/data/hyperspectral1.tif&b=16&b=10&b=7&vmin=790&vmin=855&vmin=634&vmax=4178&vmax=2912&vmax=2197"
false_url = "http://localhost:5000/{z}/{x}/{y}?url=/data/hyperspectral1.tif&&b=27&b=20&b=11&vmin=1460&vmin=1427&vmin=1131&vmax=2898&vmax=3510&vmax=2475"
ndvi_url = "http://localhost:5000/{z}/{x}/{y}?url=/data/ndvi.tif&vmin=0&vmax=1&colormap=ylgnbu"
layer_defs = {
'Natural': dict(
visible = solara.reactive(True),
opacity = solara.reactive(1.0),
url = solara.reactive(natural_url),
bounds = bounds,
),
'NDVI': dict(
visible = solara.reactive(True),
opacity = solara.reactive(1.0),
url = solara.reactive(ndvi_url),
bounds = bounds,
colormap = solara.reactive("ylgnbu"),
vmin = solara.reactive(0.),
vmax = solara.reactive(1.),
),
'False color': dict(
visible = solara.reactive(True),
opacity = solara.reactive(1.0),
url = solara.reactive(false_url),
bounds = bounds,
lookup_index_by_band = {f"b{n}":n for n in range(1,32)},
lookup_band_by_index = {n:f"b{n}" for n in range(1,32)},
bands = {
"r": dict(band=solara.reactive('b27'), vmin=solara.reactive(1460), vmax=solara.reactive(2898)),
"g": dict(band=solara.reactive('b20'), vmin=solara.reactive(1427), vmax=solara.reactive(3510)),
"b": dict(band=solara.reactive('b11'), vmin=solara.reactive(1131), vmax=solara.reactive(2475))
}
)
}
center = solara.reactive((30,38))
zoom = solara.reactive(12)
@solara.component
def Page():
layers = [
ipyleaflet.TileLayer.element(
url = layer['url'].value,
opacity = layer['opacity'].value,
visible = layer['visible'].value
)
for _, layer in layer_defs.items()
]
with solara.Columns([1,2]): # Give 1/3 of the width to the first column (Control), 2/3 to the second (Map)
LayersControl(layer_defs,
colormaps=colormaps,
available_colormaps=available_colormaps
)
ipyleaflet.Map.element(
scroll_wheel_zoom = True,
center = center.value,
on_center = center.set,
zoom = zoom.value,
on_zoom = zoom.set,
layers = layers,
controls = []
)
Page()