Rendering PC vector tiles with ipyleaflet/leafmap #175
-
Excited to see the new release with vector tile support. I would like to add functionality to leafmap for supporting PC vector tiles. This example works (adapted from an ipyleaflet example): import leafmap
m = leafmap.Map()
url = 'https://tile.nextzen.org/tilezen/vector/v1/512/all/{z}/{x}/{y}.mvt?api_key=gCZXZglvRQa6sB2z7JzL1w'
attribution = "Nextzen"
vector_tile_layer_styles = {}
m.add_vector_tile_layer(url, attribution, vector_tile_layer_styles)
m This example does not work. The vector tile does not render m = leafmap.Map()
url = 'https://planetarycomputer.microsoft.com/api/data/v1/vector/collections/ms-buildings/tilesets/United%20States_2022-06-14/tiles/{z}/{x}/{y}'
attribution = "Microsoft"
vector_tile_layer_styles = {}
m.add_vector_tile_layer(url, attribution, vector_tile_layer_styles)
m |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thanks @giswqs. I think that this should work for you:
For this specific dataset, the tiles are a collection-level asset. You can get that URL programatically with import requests
import pystac_client
catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1/")
asset_href = catalog.get_collection("ms-buildings").assets["global-footprints"].href
url = requests.get(asset_href).json()["tiles"][0] When zoomed all the way out things seem a bit slow to update, but it gets better when zoomed in. |
Beta Was this translation helpful? Give feedback.
-
@TomAugspurger Thanks for providing the URL. It works now. One issue I notice is that the tile does not render when zoom level >13. I guess this is an ipyleaflet issue. Adding parameters like import ipyleaflet
m = ipyleaflet.Map(center=(40, -100), zoom=4, scroll_wheel_zoom=True)
url = 'https://planetarycomputer.microsoft.com/api/data/v1/vector/collections/ms-buildings/tilesets/global-footprints/tiles/{z}/{x}/{y}'
layer = ipyleaflet.VectorTileLayer(url=url, attribution='Microsoft', max_native_zoom=20, max_zoom=20)
m.add(layer)
m |
Beta Was this translation helpful? Give feedback.
Thanks @giswqs. I think that this should work for you:
For this specific dataset, the tiles are a collection-level asset. You can get that URL programatically with