Closed giswqs closed 10 months ago
Another JS library that can be used for this: https://github.com/protomaps/protomaps-leaflet
Got a working protomaps-leaflet in the following commit: https://github.com/jupyter-widgets/ipyleaflet/commit/cafc323ab3cdceae4a47e883859f51f4c46cfd82
But facing the same issue that there isn't a simple way styling it
Amazing work! That's one big step forward. I am excited
@giswqs Pushed a working version with styling to https://github.com/jtmiclat/ipyleaflet/tree/pmtiles. Feel free to merge that branch here. I learned that protomaps-leaflet had a function to convert simple mapbox styles to protomap styles. Might propagate that change to folium-pmtiles
Example usage:
from ipyleaflet import Map, PMTilesLayer
m = Map(center=[43.7798, 11.24148], zoom=13)
vl = PMTilesLayer(url="https://pmtiles.jtmiclat.me/protomaps(vector)ODbL_firenze.pmtiles",
style={
"layers": [
{
"id": "landuse",
"source": "example_source",
"source-layer": "landuse",
"type": "fill",
"paint": {"fill-color": "black"},
},
{
"id": "roads",
"source": "example_source",
"source-layer": "roads",
"type": "line",
"paint": {"line-color": "steelblue"},
},
],
})
m.add_layer(vl)
m
Based on https://github.com/protomaps/protomaps-leaflet/issues/112 this function will be removed in the future though!
@jtmiclat Sorry for the delay! I have incorporated your code into this PR. Thank you very much for your help with this.
@martinRenou The new feature allows ipyleaflet to visualize large vector datasets. It will greatly benefit the geospatial community. The unit tests have all passed. Please review it when you have time.
Just added a notebook example for visualizing a 1.1 GB PMTiles.
from ipyleaflet import Map, basemaps, PMTilesLayer
m = Map(center=[52.963529, 4.776306], zoom=7, basemap=basemaps.CartoDB.DarkMatter, scroll_wheel_zoom=True)
m.layout.height = '600px'
vl = PMTilesLayer(url="https://storage.googleapis.com/ahp-research/overture/pmtiles/overture.pmtiles",
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"},
},
],
})
m.add(vl)
m
https://github.com/jupyter-widgets/ipyleaflet/assets/5016453/45985dc8-6aa3-4159-925d-00afb2929a58
Can one of the maintainers review and merge this PR?
It would be great if this PR can be included in the next release
PMTiles is a single-file archive format for tiled data. A PMTiles archive can be hosted on a commodity storage platform such as S3, and enables low-cost, zero-maintenance map applications that are "serverless" - free of a custom tile backend or third party provider.
Currently, it is challenging to render large vector datasets with ipyleaflet. PMTiles can be a great option for rendering large vector datasets with ipyleaflet. The folium-pmtiles package supports rendering PMTiles with folium. See below for an example.
This PR tries to add ipyleaflet support for PMTiles. However, I have very limited JavaScript knowledge. I need your help. Thanks.
@martinRenou @davidbrochart @jtmiclat @bdon
https://github.com/protomaps/PMTiles/discussions/209 https://github.com/jupyter-widgets/ipyleaflet/issues/1134