Skip to content

Commit 3b20a05

Browse files
Forward unrecognised Leaflet options in path_options
path_options pops the options it knows about and builds the result from those, but never forwards the remaining kwargs. Leaflet Path options that it does not name explicitly -- interactive, pane, renderer, attribution and so on -- were therefore silently dropped from every vector overlay (Circle, CircleMarker, PolyLine, Polygon, Rectangle). This is inconsistent with the rest of folium: FeatureGroup, TileLayer, GeoJson and the others all forward **kwargs to Leaflet via remove_empty. The special-cased pass-through of tags, className and gradient shows the intent was to support Leaflet options, just incompletely. Forward the leftover options too, so e.g. CircleMarker(..., interactive= False) actually reaches Leaflet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent b972da7 commit 3b20a05

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

folium/vector_layers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def path_options(
123123
"bubblingMouseEvents": kwargs.pop("bubblingMouseEvents", True),
124124
}
125125
default.update(extra_options)
126+
# Pass any remaining options straight through to Leaflet, matching how
127+
# the other folium option builders forward **kwargs. Without this, Path
128+
# options such as ``interactive``, ``pane`` or ``renderer`` were silently
129+
# dropped from vector overlays.
130+
default.update(kwargs)
126131
return default
127132

128133

tests/test_vector_layers.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,31 @@ def test_path_options_lower_camel_case():
404404
options = path_options(fill_color="red", fillOpacity=0.3)
405405
assert options["fillColor"] == "red"
406406
assert options["fillOpacity"] == 0.3
407+
408+
409+
def test_path_options_passes_through_extra_leaflet_options():
410+
"""Leaflet Path options not named explicitly should not be dropped.
411+
412+
``interactive``, ``pane``, ``renderer`` and friends used to vanish from
413+
vector overlays even though the other folium option builders forward
414+
arbitrary **kwargs to Leaflet.
415+
"""
416+
options = path_options(
417+
line=False,
418+
radius=10,
419+
interactive=False,
420+
pane="overlayPane",
421+
custom_option="x",
422+
)
423+
assert options["interactive"] is False
424+
assert options["pane"] == "overlayPane"
425+
# snake_case is camelised like the named options
426+
assert options["customOption"] == "x"
427+
428+
429+
def test_circle_marker_forwards_interactive():
430+
m = Map()
431+
marker = CircleMarker(location=[0, 0], radius=5, interactive=False)
432+
marker.add_to(m)
433+
rendered = normalize(m._parent.render())
434+
assert '"interactive": false' in rendered

0 commit comments

Comments
 (0)