Skip to content

Invalid Zoom for TileLayer in version 0.19.0 #2043

Closed

Description

@pmd84

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

Activity

  1. lux-orc commented on Dec 10, 2024

    @lux-orc

    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.

  2. hansthen commented on Dec 11, 2024

    @hansthen
    Collaborator

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

  3. added
    bugAn issue describing unexpected or malicious behaviour
    on Dec 11, 2024
  4. Conengmo commented on Dec 11, 2024

    @Conengmo
    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.

  5. lux-orc commented on Dec 11, 2024

    @lux-orc

    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 :)

  6. Conengmo commented on Dec 12, 2024

    @Conengmo
    Member

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

  7. lux-orc commented on Dec 12, 2024

    @lux-orc

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue describing unexpected or malicious behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions