-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for PMTiles #1138
Add support for PMTiles #1138
Conversation
Another JS library that can be used for this: https://github.com/protomaps/protomaps-leaflet |
@@ -16,6 +16,7 @@ require('leaflet-fullscreen'); | |||
require('leaflet-transform'); | |||
require('leaflet.awesome-markers'); | |||
require('leaflet-search'); | |||
require('protomaps-leaflet'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for general purpose vector tile display, maplibre is better than protomaps-leaflet, is it possible to use that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used maplibre in the initial commit, but it failed. I don't how to fix it, so I changed to back to protomaps-leaflet. See
92586cd#diff-ab455b4e55f1402a4baec5dd7dd302a20e715e7b3897e82cc2e4b6ac557baba8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For references on how styling vector tiles works with ipyleaflet. https://ipyleaflet.readthedocs.io/en/latest/layers/vector_tile.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i ended up using protomaps-leaflet's json_style function to convert mapbox style specs to protomaps style
I found trying to use maplibre is super hacky with overlays and for the case of ipyleaflet adds a large js dependency on build time for an optional feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the json_style only parses a small subset of mapbox style specs. I don't have the time or resources to bring that to a complete state (the spec is very complex - look at https://github.com/openlayers/ol-mapbox-style for a comparison), which is why I would rather remove the feature instead of confusing developers as to why their JSON styles don't work. I may re-evaluate this, but in general the state of protomaps-leaflet is frozen as the majority of use cases have moved to MapLibre. This could change if a company or institution wants to sponsor the continued development of the protomaps-leaflet engine, a good use case may be these notebooks.
Got a working protomaps-leaflet in the following commit: cafc323 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 protomaps/protomaps-leaflet#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 Peek.2023-10-15.00-10.mp4 |
Can one of the maintainers review and merge this PR? |
It would be great if this PR can be included in the next release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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
protomaps/PMTiles#209
#1134