Skip to content
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 ipyleaflet support for PMTiles #575

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions leafmap/leafmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,56 @@ def add_vector_tile(

add_vector_tile_layer = add_vector_tile

def add_pmtiles(
self,
url,
style={},
name="PMTiles",
show=True,
zoom_to_layer=True,
**kwargs,
):
"""
Adds a PMTiles layer to the map. This function is not officially supported yet by ipyleaflet yet.
Install it with the following command:
pip install git+https://github.com/giswqs/ipyleaflet.git@pmtiles

Args:
url (str): The URL of the PMTiles file.
style (str, optional): The CSS style to apply to the layer. Defaults to None.
See https://docs.mapbox.com/style-spec/reference/layers/ for more info.
name (str, optional): The name of the layer. Defaults to None.
show (bool, optional): Whether the layer should be shown initially. Defaults to True.
zoom_to_layer (bool, optional): Whether to zoom to the layer extent. Defaults to True.
**kwargs: Additional keyword arguments to pass to the PMTilesLayer constructor.

Returns:
None
"""

try:
if "sources" in kwargs:
del kwargs["sources"]

if "version" in kwargs:
del kwargs["version"]

layer = ipyleaflet.PMTilesLayer(
url=url,
style=style,
name=name,
visible=show,
**kwargs,
)
self.add(layer)

if zoom_to_layer:
metadata = pmtiles_metadata(url)
bounds = metadata["bounds"]
self.zoom_to_bounds(bounds)
except Exception as e:
print(e)

def add_osm_from_geocode(
self,
query,
Expand Down