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

Invalid Zoom for TileLayer in version 0.19.0 #2043

Closed
pmd84 opened this issue Dec 10, 2024 · 6 comments · Fixed by #2044
Closed

Invalid Zoom for TileLayer in version 0.19.0 #2043

pmd84 opened this issue Dec 10, 2024 · 6 comments · Fixed by #2044
Labels
bug An issue describing unexpected or malicious behaviour

Comments

@pmd84
Copy link

pmd84 commented Dec 10, 2024

I'm using a tiling endpoint based of TiTiler to serve map tiles on Folium. Since the upgrade last night, the tiles no longer render, and my tiling endpoint gives me this error: "Invalid ZOOM level 0", and the tile request is showing as "tiles/WebMercatorQuad/0/0/0"

geom = shape(AOI)
centroid = geom.centroid

m = folium.Map(location=[centroid.y, centroid.x], zoom_start=12)

# Initialize Tile Layer and add to map
TileLayer(
    tiles=tilejson["tiles"][0],
    opacity=1,
    min_zoom=8,
    max_zoom=14,
    attr="Sentinel-2 COG",
).add_to(m)

folium.GeoJson(AOI).add_to(m)

m

Typically, the folium map generates tile at whatever x, y, z are visible on the map. Only this single 0,0,0 tile is being requested.

Environment is in a Databricks notebook with Folium 0.19.0

@lux-orc
Copy link

lux-orc commented Dec 10, 2024

I have got a similar issue, the following is the reproducible codes that people can test on folium 0.18.0 and 0.19.0.

import folium

# Esri_WorldTopoMap
arcgis = 'https://server.arcgisonline.com/ArcGIS/rest/services'
esri = {'Esri_WorldTopoMap': 'World_Topo_Map'}
tile = 'MapServer/tile/{z}/{y}/{x}'
tile_esri = dict(zip(esri.keys(), ['/'.join([arcgis, v, tile]) for v in esri.values()]))

# GOOGLE online map
tile_google = {
    'Maps': 'https://mt1.google.com/vt/lyrs=r&x={x}&y={y}&z={z}',
    'Satellite': 'http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}',
    'Roads': 'https://mt1.google.com/vt/lyrs=h&x={x}&y={y}&z={z}',
}

m = folium.Map(
    location=(-45.54, 169.74),
    tiles=None,
    zoom_start=9,
    zoom_control=False,
    attributionControl=False,
)

# Add 'Esri_WorldTopoMap' as 'Esri_WorldTopoMap'
folium.raster_layers.TileLayer(
    tiles=tile_esri['Esri_WorldTopoMap'],
    attr='Esri_WorldTopoMap',
    name='World Topographic Map (ESRI)',
    overlay=False,  # As an optional overlay (True) or the base layer (False)
    control=True,  # Whether the Layer will be included in LayerControls
    show=True,
).add_to(m)

# Add Google Maps
folium.raster_layers.TileLayer(
    tiles='http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
    attr='Google',
    name='Google Maps',
    subdomains=['mt0', 'mt1', 'mt2', 'mt3'],
    overlay=False,
    control=True,
    show=False,
).add_to(m)

# Add Google Satellite
folium.raster_layers.TileLayer(
    tiles='http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
    attr='Google',
    name='Google Satellite',
    subdomains=['mt0', 'mt1', 'mt2', 'mt3'],
    overlay=False,
    control=True,
    show=False,
).add_to(m)

# Add Google Roads layer (optional)
folium.raster_layers.TileLayer(
    tiles=tile_google['Roads'],
    attr='Google',
    name='Google Roads',
    overlay=True,
    control=True,
    show=False,
).add_to(m)

folium.LayerControl(position='bottomright', collapsed=False).add_to(m)

m

The folium map can be shown properly in jupyter notebook when using 0.18.0. However, you will have a map with some possible render issue when using 0.19.0

Hopefully, the issue is clearly illustrated.

@hansthen
Copy link
Collaborator

I will have a look one of these days to see what can be the issue.

@Conengmo Conengmo added the bug An issue describing unexpected or malicious behaviour label Dec 11, 2024
@Conengmo
Copy link
Member

Thanks @lux-orc for the reproducible example, very useful. The issue seems to be with the maxNativeZoom parameter which is set to null. This is likely caused by #2029.

Before we used a parse_options function, which discarded option values that were None. This check isn't applied in the new to_javascript filter. I'll make a PR with a possible fix.

@lux-orc
Copy link

lux-orc commented Dec 11, 2024

Thanks @lux-orc for the reproducible example, very useful. The issue seems to be with the maxNativeZoom parameter which is set to null. This is likely caused by #2029.

Before we used a parse_options function, which discarded option values that were None. This check isn't applied in the new to_javascript filter. I'll make a PR with a possible fix.

Thank you for working on this @Conengmo. Looking forward to having the fix :)

@Conengmo
Copy link
Member

Just released v0.19.1 with a fix for this issue, hopefully that solves it for you. Thanks again for the bug report!

@lux-orc
Copy link

lux-orc commented Dec 12, 2024

Just released v0.19.1 with a fix for this issue, hopefully that solves it for you. Thanks again for the bug report!

I just installed Folium 0.19.1 using pip—it works! Thank you so much for your time on this quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing unexpected or malicious behaviour
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants