folium: Vector tile does not render when zoom level greater than 14

Describe the bug The vector tile layer does not render when zoom level is great than 14. @iwpnd

To Reproduce https://nbviewer.org/github/python-visualization/folium/blob/main/examples/plugin-vector-tiles.ipynb

import folium
from folium.plugins import VectorGridProtobuf
url = "https://vectortiles3.geo.admin.ch/tiles/ch.swisstopo.leichte-basiskarte.vt/v1.0.0/{z}/{x}/{y}.pbf"
m = folium.Map(location=[46.8, 8.2], zoom_start=14)

options = {'maxNativeZoom': 20, 'maxZoom': 20}
# options = {'max_native_zoom': 20, 'max_zoom': 20} #not working either

vc = VectorGridProtobuf(url, "vector tile", options)
m.add_child(vc)
m

Peek 2023-01-27 09-38

Expected behavior The vector tile layer should render in a zoom level much larger than 14 so that we can see the details of vector data.

Environment (please complete the following information):

  • Python version: 3.9
  • folium version: 0.13.0

Possible solutions The leaflet VectorGrid.Protobuf example appears to have the maxNativeZoom parameter. I am not sure if the folium plugin can pass the maxNativeZoom and maxZoom parameters to VectorGrid.Protobuf.

https://leaflet.github.io/Leaflet.VectorGrid/vectorgrid-api-docs.html

L.vectorGrid.protobuf("https://free-{s}.tilehosting.com/data/v3/{z}/{x}/{y}.pbf.pict?key={key}", {
    vectorTileLayerStyles: { ... },
    subdomains: "0123",
    key: 'abcdefghi01234567890',
    maxNativeZoom: 14
}).addTo(map);

Relevant issues https://github.com/microsoft/PlanetaryComputer/discussions/175 @TomAugspurger

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 22 (20 by maintainers)

Most upvoted comments

https://pypi.org/project/folium-vectortilelayer/

for whoever is interested.

thank you @jkuebart for the plugin and your input here 🙏

@iwpnd Yes, I tested it. I think the most critical parameter is maxDetailZoom. If it is larger than the max zoom level provided by source, the vector tile layer won’t render. If it is smaller than the max zoom level provided by source, the polygons will be simplified. So users will have to do trial and error to figure out the optimal maxDetailZoom.

The maxZoom parameter controls the zoom in button of the Zoom Control. It disables the zoom-in button when the map zoom level is larger than maxZoom. It does not really affect the vector tile rendering.

I didn’t follow this discussion too closely as I don’t know about folium, but there shouldn’t be much »trial and error« involved in setting the zoom parameters.

If the server serves tiles for the full range of max/minZoom levels, there’s really no reason to use any of the other options. If the server lacks some zoom levels, Leaflet.VectorTileLayer offers two possible solutions:

  • Using max/minNativeZoom, the tiles on zoom levels outside the given range are loaded from the specified zoom level and scaled up or down including line widths and marker sizes. The result looks the same as it would with raster tiles without the obvious artifacts.
  • Using max/minDetailZoom, the tiles on zoom levels outside the given range are loaded from the specified zoom level and drawn larger or smaller while keeping the same line widths and marker sizes. The result looks as if the tile with the target zoom level was available, but obviously the amount of detail remains the same.

max/minZoom and max/minNativeZoom work as documented for L.GridLayer, to quote:

  • maxZoom The maximum zoom level up to which this layer will be displayed (inclusive).
  • minZoom The minimum zoom level down to which this layer will be displayed (inclusive).
  • maxNativeZoom Maximum zoom number the tile source has available. If it is specified, the tiles on all zoom levels higher than maxNativeZoom will be loaded from maxNativeZoom level and auto-scaled.
  • minNativeZoom Minimum zoom number the tile source has available. If it is specified, the tiles on all zoom levels lower than minNativeZoom will be loaded from minNativeZoom level and auto-scaled.

Leaflet.VectorTileLayer adds max/minDetailZoom which is documented here.