-
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
Merged
Merged
Add support for PMTiles #1138
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
92586cd
Add support for PMTiles
giswqs a34d3bf
Fix yarnpkg error
giswqs 6261995
Fix package.json
giswqs d1370ca
Remove maplibre-gl-leaflet
giswqs 974af2b
Update package
giswqs 93048f4
Fix linter issue
giswqs 2070e94
Fix linter issue
giswqs ba3cd8d
Change layer view
giswqs abf9805
Incorporate jtmiclat code
giswqs b0aa5d7
Add PMTiles notebook
giswqs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Set up for JupyterLite\n", | ||
"try:\n", | ||
" import piplite\n", | ||
" await piplite.install('ipyleaflet')\n", | ||
"except ImportError:\n", | ||
" pass" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ipyleaflet import Map, basemaps, PMTilesLayer" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m = Map(center=[52.963529, 4.776306], zoom=7, basemap=basemaps.CartoDB.DarkMatter, scroll_wheel_zoom=True)\n", | ||
"m.layout.height = '600px'\n", | ||
"\n", | ||
"vl = PMTilesLayer(url=\"https://storage.googleapis.com/ahp-research/overture/pmtiles/overture.pmtiles\", \n", | ||
" style = {\n", | ||
" \"layers\": [\n", | ||
" {\n", | ||
" \"id\": \"admins\",\n", | ||
" \"source\": \"example_source\",\n", | ||
" \"source-layer\": \"admins\",\n", | ||
" \"type\": \"fill\",\n", | ||
" \"paint\": {\"fill-color\": \"#BDD3C7\", \"fill-opacity\": 0.1},\n", | ||
" },\n", | ||
" {\n", | ||
" \"id\": \"buildings\",\n", | ||
" \"source\": \"example_source\",\n", | ||
" \"source-layer\": \"buildings\",\n", | ||
" \"type\": \"fill\",\n", | ||
" \"paint\": {\"fill-color\": \"#FFFFB3\", \"fill-opacity\": 0.5},\n", | ||
" },\n", | ||
" {\n", | ||
" \"id\": \"places\",\n", | ||
" \"source\": \"example_source\",\n", | ||
" \"source-layer\": \"places\",\n", | ||
" \"type\": \"fill\",\n", | ||
" \"paint\": {\"fill-color\": \"#BEBADA\", \"fill-opacity\": 0.5},\n", | ||
" },\n", | ||
" {\n", | ||
" \"id\": \"roads\",\n", | ||
" \"source\": \"example_source\",\n", | ||
" \"source-layer\": \"roads\",\n", | ||
" \"type\": \"line\",\n", | ||
" \"paint\": {\"line-color\": \"#FB8072\"},\n", | ||
" },\n", | ||
" ],\n", | ||
" })\n", | ||
"m.add(vl)\n", | ||
"m" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
const layer = require('./Layer.js'); | ||
const protomapsL = require('protomaps-leaflet'); | ||
|
||
export class LeafletPMTilesLayerModel extends layer.LeafletLayerModel { | ||
defaults() { | ||
return { | ||
...super.defaults(), | ||
_view_name: 'LeafletPMTilesLayerView', | ||
_model_name: 'LeafletPMTilesLayerModel', | ||
url: '', | ||
attribution: '', | ||
style: {}, | ||
}; | ||
} | ||
} | ||
|
||
export class LeafletPMTilesLayerView extends layer.LeafletLayerView { | ||
create_obj() { | ||
var options = { | ||
...this.get_options(), | ||
url: this.model.get('url'), | ||
...protomapsL.json_style(this.model.get('style')), | ||
}; | ||
this.obj = protomapsL.leafletLayer(options); | ||
} | ||
|
||
model_events() { | ||
super.model_events(); | ||
this.listenTo( | ||
this.model, | ||
'change:url', | ||
function () { | ||
this.obj.setUrl(this.model.get('url')); | ||
}, | ||
this | ||
); | ||
} | ||
|
||
handle_message(content) { | ||
if (content.msg == 'add_inspector') { | ||
this.obj.addInspector(this.map_view.obj); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
jtmiclat@c101c87
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.