Skip to content

Camelize MiniMap tile layer options - #2371

Open
KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:minimap-tile-options
Open

KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:minimap-tile-options

Conversation

@KhadeerBasha1232

Copy link
Copy Markdown
Contributor

Camelize MiniMap tile layer options

The problem

Options set on the tile layer passed to MiniMap don't reach the minimap. For example, with 512px tiles (common for Mapbox styles):

import folium
from folium.plugins import MiniMap

kw = dict(
    tiles="https://tile.openstreetmap.org/{z}/{x}/{y}.png",
    attr="© OpenStreetMap contributors",
    tile_size=512,
    zoom_offset=-1,
)
m = folium.Map(location=(48.8566, 2.3522), zoom_start=12, tiles=None)
folium.TileLayer(**kw).add_to(m)
MiniMap(tile_layer=folium.TileLayer(**kw), width=300, height=300, zoom_level_offset=-3).add_to(m)
m.save("map.html")

The main map uses 512px tiles, but the minimap still loads 256px tiles from a different zoom level. In the browser, the minimap's layer has tileSize: 256, zoomOffset: 0.

The cause

TileLayer stores its options in snake_case and renders them with tojavascript, which camelizes the keys. The MiniMap template renders the same options with tojson:

L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png",
    {"attribution": "...", "detect_retina": false, "max_native_zoom": 18, "max_zoom": 18,
     "min_zoom": 0, "no_wrap": false, ..., "tile_size": 512, "zoom_offset": -1});

Leaflet ignores tile_size, zoom_offset, max_native_zoom, max_zoom, min_zoom, detect_retina, no_wrap and any other multi-word key passed as a kwarg.

The fix

Use tojavascript in the MiniMap template, matching TileLayer's own template.

Before / after

The example above, opened in Chrome:

Before After
Minimap showing 256px tiles with tiny labels Minimap showing 512px tiles matching the main map

Tests

Added test_minimap_tile_layer_options_are_camelized to tests/plugins/test_minimap.py. It fails without the fix.

The MiniMap template serialized its tile layer's options with tojson,
while TileLayer itself uses tojavascript. Leaflet ignored the resulting
snake_case keys (tile_size, zoom_offset, max_native_zoom, detect_retina,
no_wrap, ...), so the minimap didn't honour them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
pypi — c71583e7 Deployed Nov 20, 2026 by KhadeerBasha1232 via packages #2128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant