Spaces:
Running
Running
Add pmtiles
Browse files- Dockerfile +1 -0
- pages/03_pmtiles.py +88 -0
Dockerfile
CHANGED
|
@@ -16,6 +16,7 @@ USER root
|
|
| 16 |
RUN chown -R ${NB_UID} ${HOME}
|
| 17 |
RUN apt-get update && apt-get install -y git
|
| 18 |
RUN pip install -U git+https://github.com/giswqs/ipyleaflet.git@pmtiles
|
|
|
|
| 19 |
USER ${NB_USER}
|
| 20 |
|
| 21 |
EXPOSE 8765
|
|
|
|
| 16 |
RUN chown -R ${NB_UID} ${HOME}
|
| 17 |
RUN apt-get update && apt-get install -y git
|
| 18 |
RUN pip install -U git+https://github.com/giswqs/ipyleaflet.git@pmtiles
|
| 19 |
+
RUN pip install -U git+https://github.com/opengeos/leafmap.git
|
| 20 |
USER ${NB_USER}
|
| 21 |
|
| 22 |
EXPOSE 8765
|
pages/03_pmtiles.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import leafmap
|
| 2 |
+
import solara
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
zoom = solara.reactive(2)
|
| 6 |
+
center = solara.reactive((20, 0))
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Map(leafmap.Map):
|
| 10 |
+
def __init__(self, **kwargs):
|
| 11 |
+
super().__init__(**kwargs)
|
| 12 |
+
# Add what you want below
|
| 13 |
+
|
| 14 |
+
self.add_basemap('CartoDB.DarkMatter')
|
| 15 |
+
url = "https://storage.googleapis.com/ahp-research/overture/pmtiles/overture.pmtiles"
|
| 16 |
+
|
| 17 |
+
style={
|
| 18 |
+
"version": 8,
|
| 19 |
+
"sources": {
|
| 20 |
+
"example_source": {
|
| 21 |
+
"type": "vector",
|
| 22 |
+
"url": "pmtiles://" + url,
|
| 23 |
+
"attribution": 'PMTiles',
|
| 24 |
+
}
|
| 25 |
+
},
|
| 26 |
+
"layers": [
|
| 27 |
+
{
|
| 28 |
+
"id": "admins",
|
| 29 |
+
"source": "example_source",
|
| 30 |
+
"source-layer": "admins",
|
| 31 |
+
"type": "fill",
|
| 32 |
+
"paint": {"fill-color": "#BDD3C7", "fill-opacity": 0.1},
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"id": "buildings",
|
| 36 |
+
"source": "example_source",
|
| 37 |
+
"source-layer": "buildings",
|
| 38 |
+
"type": "fill",
|
| 39 |
+
"paint": {"fill-color": "#FFFFB3", "fill-opacity": 0.5},
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"id": "places",
|
| 43 |
+
"source": "example_source",
|
| 44 |
+
"source-layer": "places",
|
| 45 |
+
"type": "fill",
|
| 46 |
+
"paint": {"fill-color": "#BEBADA", "fill-opacity": 0.5},
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"id": "roads",
|
| 50 |
+
"source": "example_source",
|
| 51 |
+
"source-layer": "roads",
|
| 52 |
+
"type": "line",
|
| 53 |
+
"paint": {"line-color": "#FB8072"},
|
| 54 |
+
},
|
| 55 |
+
],
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
self.add_pmtiles(url, name='PMTiles', style=style)
|
| 59 |
+
|
| 60 |
+
legend_dict = {
|
| 61 |
+
'admins': 'BDD3C7',
|
| 62 |
+
'buildings': 'FFFFB3',
|
| 63 |
+
'places': 'BEBADA',
|
| 64 |
+
'roads': 'FB8072',
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
self.add_legend(legend_dict=legend_dict)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
@solara.component
|
| 71 |
+
def Page():
|
| 72 |
+
with solara.Column(style={"min-width": "500px"}):
|
| 73 |
+
# solara components support reactive variables
|
| 74 |
+
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
| 75 |
+
# using 3rd party widget library require wiring up the events manually
|
| 76 |
+
# using zoom.value and zoom.set
|
| 77 |
+
Map.element( # type: ignore
|
| 78 |
+
zoom=zoom.value,
|
| 79 |
+
on_zoom=zoom.set,
|
| 80 |
+
center=center.value,
|
| 81 |
+
on_center=center.set,
|
| 82 |
+
scroll_wheel_zoom=True,
|
| 83 |
+
toolbar_ctrl=False,
|
| 84 |
+
data_ctrl=False,
|
| 85 |
+
height="780px",
|
| 86 |
+
)
|
| 87 |
+
solara.Text(f"Zoom: {zoom.value}")
|
| 88 |
+
solara.Text(f"Center: {center.value}")
|