From 157d46a15bc37b11c63f748cbb34b956bcb29fb7 Mon Sep 17 00:00:00 2001 From: nina-mir Date: Fri, 7 Aug 2026 17:18:42 -0700 Subject: [PATCH 1/3] Propagate feature to child layers of multi-geometries Leaflet's geometryToLayer returns a FeatureGroup for MultiPoint, and addData assigns `feature` to that group only. Tooltips resolve their source to the layer that fired the event (Tooltip.js:418, v1.9.3), which is a child marker with no `feature`, so GeoJsonTooltip and GeoJsonPopup throw and never render. Copy the feature onto child layers in onEachFeature, before any user-supplied callback, so both see the same data. Fixes #1520 --- folium/features.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/folium/features.py b/folium/features.py index 65b6da9475..3b9b3ea433 100644 --- a/folium/features.py +++ b/folium/features.py @@ -586,6 +586,11 @@ class GeoJson(Layer): {%- endif %} function {{this.get_name()}}_onEachFeature(feature, layer) { + if (typeof layer.eachLayer === "function") { + layer.eachLayer(function (child) { + if (child.feature === undefined) { child.feature = feature; } + }); + } {%- if this.on_each_feature %} ({{this.on_each_feature}})(feature, layer); {%- endif %} From 7372559ca535630e919ad2661f3475b496749a39 Mon Sep 17 00:00:00 2001 From: nina-mir Date: Fri, 7 Aug 2026 19:29:02 -0700 Subject: [PATCH 2/3] Descend into nested groups when propagating features A GeometryCollection containing a MultiPoint produces a FeatureGroup inside a FeatureGroup, placing the hovered marker two levels below the layer that owns `feature`. eachLayer only iterates one level, so the propagation now recurses. --- folium/features.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/folium/features.py b/folium/features.py index 3b9b3ea433..b04c924884 100644 --- a/folium/features.py +++ b/folium/features.py @@ -586,11 +586,13 @@ class GeoJson(Layer): {%- endif %} function {{this.get_name()}}_onEachFeature(feature, layer) { - if (typeof layer.eachLayer === "function") { - layer.eachLayer(function (child) { + (function propagate(parent){ + if (typeof parent.eachLayer !== "function") {return;} + parent.eachLayer(function (child) { if (child.feature === undefined) { child.feature = feature; } - }); - } + propagate(child); + }) + })(layer) {%- if this.on_each_feature %} ({{this.on_each_feature}})(feature, layer); {%- endif %} From 1ba22f37277602b9634b06b0622d18d6edcc9f79 Mon Sep 17 00:00:00 2001 From: nina-mir Date: Sat, 8 Aug 2026 19:42:04 -0700 Subject: [PATCH 3/3] Add regression test for MultiPoint tooltips --- .../test_multipoints_tooltip_selenium.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/selenium/test_multipoints_tooltip_selenium.py diff --git a/tests/selenium/test_multipoints_tooltip_selenium.py b/tests/selenium/test_multipoints_tooltip_selenium.py new file mode 100644 index 0000000000..76d3ad4566 --- /dev/null +++ b/tests/selenium/test_multipoints_tooltip_selenium.py @@ -0,0 +1,65 @@ +import folium +from folium import GeoJson, GeoJsonTooltip, Map +from folium.utilities import temp_html_filepath + +# Selenium's pointer actions do not reliably reach Leaflet's SVG paths in +# headless Chrome, so the hover is dispatched as a DOM event instead. It +# bubbles through Map._handleDOMEvent exactly as a real pointer hover does. +HOVER = """ + const el = arguments[0]; + const rect = el.getBoundingClientRect(); + const opts = { + bubbles: true, + clientX: rect.x + rect.width / 2, + clientY: rect.y + rect.height / 2, + }; + el.dispatchEvent(new MouseEvent('mouseover', opts)); + el.dispatchEvent(new MouseEvent('mousemove', opts)); +""" + + +def build() -> Map: + data = { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {"name": "multipoint"}, + "geometry": {"type": "MultiPoint", "coordinates": [[0.0, 0.0]]}, + } + ], + } + m = Map((0, 0), zoom_start=10) + GeoJson( + data, + marker=folium.CircleMarker(radius=20), + tooltip=GeoJsonTooltip(fields=["name"], labels=False), + ).add_to(m) + return m + + +def test_geojson_multipoint_tooltip(driver): + """A GeoJsonTooltip must render for MultiPoint geometry. + + Leaflet returns a FeatureGroup for MultiPoint and assigns `feature` to + that group only, while the tooltip resolves its source to the child + layer that fired the event. Without the feature on the children, the + tooltip's content function throws and nothing renders. + + https://github.com/python-visualization/folium/issues/1520 + """ + html = build().get_root().render() + with temp_html_filepath(html) as filepath: + driver.get_file(filepath) + driver.wait_until(".folium-map") + + marker = driver.wait_until("path.leaflet-interactive") + driver.execute_script(HOVER, marker) + + tooltip = driver.wait_until(".leaflet-tooltip.foliumtooltip") + assert "multipoint" in tooltip.text + + # No verify_js_logs() here: Leaflet 1.9.3 (our pin) throws + # "t.getElement is not a function" from _addFocusListenersOnLayer for any + # GeoJSON layer containing a nested FeatureGroup, independent of this fix. + # Guarded upstream in 1.9.4.