Skip to content

Commit

Permalink
Add ipyleaflet support for PMTiles
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Oct 16, 2023
1 parent a76d49b commit 9d5ecca
Showing 1 changed file with 50 additions and 0 deletions.
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

0 comments on commit 9d5ecca

Please sign in to comment.