import solara
import ipyleaflet
from utils import update_url, get_layer_url_update_options
from components import LayersControl
import json
with open('colormaps.json') as f:
available_colormaps = json.load(f)
colormaps = [key for key in available_colormaps]
colorbar_kwargs=dict(
length=250, # width in pixels
orientation='horizontal',
breadth=15, # How "thick" is the colorbar itself
padding=10,
axis_padding=6,
)
layer_definitions = {
'Natural': dict(
base_url = "http://localhost:5000/{z}/{x}/{y}?url=/data/hyperspectral1.tif",
visible = solara.reactive(True),
opacity = solara.reactive(1.0),
url = "", # 👈 Not reactive for this layer (empty for now..)
),
'NDVI': dict(
base_url = "http://localhost:5000/{z}/{x}/{y}?url=/data/ndvi.tif",
visible = solara.reactive(True),
opacity = solara.reactive(1.0),
url = solara.reactive("http://localhost:5000/{z}/{x}/{y}?url=%2Fdata%2Fndvi.tif&colormap=ylgnbu&vmin=0.0&vmax=1.0"),
# Optional:
url_options = dict(
colormap = solara.reactive("ylgnbu"),
vmin = solara.reactive(0.),
vmax = solara.reactive(1.)
)
)
}
layer_definitions['Natural']['url'] = update_url(
layer_definitions['Natural']['base_url'],
dict(b=[16,10,7],vmin=[790,855,634], vmax=[4178,2912,2197])
)
center = solara.reactive((30,38))
zoom = solara.reactive(12)
@solara.component
def Page():
layers = [
ipyleaflet.TileLayer.element(
url = layer['url'].value if hasattr(layer['url'], 'value') else layer['url'],
# ☝️ The Natural layer doesn't have a reactive url
opacity = layer['opacity'].value,
visible = layer['visible'].value
)
for _, layer in layer_definitions.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_definitions,
colormaps = colormaps,
available_colormaps=available_colormaps,
colorbar_kwargs=colorbar_kwargs)
ipyleaflet.Map.element(
scroll_wheel_zoom = True,
center = center.value,
on_center = center.set,
zoom = zoom.value,
on_zoom = zoom.set,
layers = layers,
)
Page()