import ipyleaflet
import leafmap
import solara
zoom = solara.reactive(2)
center = solara.reactive((20, 0))
class Map(leafmap.Map):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.add_basemap("SATELLITE")
self.add_ftw_data()
def add_ftw_data(self):
url = "https://data.source.coop/kerner-lab/fields-of-the-world/ftw-sources.pmtiles"
style = {
"version": 8,
"sources": {
"example_source": {
"type": "vector",
"url": "pmtiles://" + url,
"attribution": "PMTiles",
}
},
"layers": [
{
"id": "ftw",
"source": "example_source",
"source-layer": "ftw-sources",
"type": "line",
"paint": {
"line-color": "#ff0000",
"line-width": 2,
},
"maxzoom": 24,
},
],
}
self.add_pmtiles(url, style=style, layer_name="Field boundary", zoom_to_layer=False)
@solara.component
def Page():
with solara.Column(style={"min-width": "500px"}):
Map.element(
zoom=zoom.value,
on_zoom=zoom.set,
center=center.value,
on_center=center.set,
scroll_wheel_zoom=True,
toolbar_control=False,
draw_control=False,
height="900px"
)