Jonathan Marokhovsky
Made the cog-focused page, reorganized into more of an app framework, and updated the requirements
c140c33
raw
history blame contribute delete
No virus
2.52 kB
import leafmap
from leafmap import pmtiles_style
from reacton import component as component
import solara
import ipywidgets as widgets
# THings to come:
# TODO: Calculate some metrics given the area.
# TODO: add a raster to the toy
# TODO: Dynamically check the center of the map and change what's displayed depending on that.
# variables
zoom = solara.reactive(2)
center = solara.reactive((20, 0))
q_url = "https://storage.googleapis.com/ahp-research/overture/pmtiles/overture.pmtiles"
q_style = {
"layers": [
{
"id": "admins",
"source": "example_source",
"source-layer": "admins",
"type": "fill",
"paint": {"fill-color": "#BDD3C7", "fill-opacity": 0.1},
},
{
"id": "buildings",
"source": "example_source",
"source-layer": "buildings",
"type": "fill",
"paint": {"fill-color": "#FFFFB3", "fill-opacity": 0.5},
},
{
"id": "places",
"source": "example_source",
"source-layer": "places",
"type": "fill",
"paint": {"fill-color": "#BEBADA", "fill-opacity": 0.5},
},
{
"id": "roads",
"source": "example_source",
"source-layer": "roads",
"type": "line",
"paint": {"line-color": "#FB8072"},
},
],
}
class Map(leafmap.Map):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self.add_basemap("CartoDB.DarkMatter")
self.add_pmtiles(
q_url,
style=q_style,
name="Quisheng Layer",
overlay=True,
show=True,
zoom_to_layer=True,
)
def run_area(self):
print(self.user_roi)
@component
def Page():
with solara.Row():
solara.Button(label="Area", on_click=Map.run_area)
with solara.Column(style={"min-width": "500px"}):
# solara components support reactive variables
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
# using 3rd party widget library require wiring up the events manually
# using zoom.value and zoom.set
Map.element( # type: ignore
zoom=zoom.value,
on_zoom=zoom.set,
center=center.value,
on_center=center.set,
scroll_wheel_zoom=True,
toolbar_ctrl=False,
data_ctrl=False,
height="780px",
)