Skip to content

Issue 1520: Propagate feature to child layers of multi-geometries - #2263

Draft
nina-mir wants to merge 2 commits into
python-visualization:mainfrom
nina-mir:fix-1520-multipoint
Draft

Issue 1520: Propagate feature to child layers of multi-geometries#2263
nina-mir wants to merge 2 commits into
python-visualization:mainfrom
nina-mir:fix-1520-multipoint

Conversation

@nina-mir

@nina-mir nina-mir commented Aug 8, 2026

Copy link
Copy Markdown

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, which is a child marker with no feature, so the content function throws before rendering. This copies the feature onto child layers in onEachFeature, descending recursively so that nested groups — a GeometryCollection containing a MultiPoint — are also covered.

Draft [still to come]: a selenium regression test.

Verified in Firefox/Chrome against the reporter's snippet and a matrix of all eight geometry types. MultiLineString and MultiPolygon are unaffected, since Leaflet flattens those into a single layer rather than a group.

Geometry Leaflet returns Before After
Point, LineString, Polygon single layer works works
MultiLineString, MultiPolygon single layer (flattened) works works
MultiPoint FeatureGroup broken works
GeometryCollection FeatureGroup broken works
GeometryCollection containing MultiPoint nested FeatureGroup broken works
Console error before the fix
Uncaught TypeError: can't access property "properties", layer.feature is undefined
    <anonymous> 
    _updateContent DivOverlay.js:277
    update DivOverlay.js:187
    onAdd DivOverlay.js:113
    onAdd Tooltip.js:84
    _layerAdd Layer.js:114
    whenReady Map.js:1477
    addLayer Layer.js:172
    openOn DivOverlay.js:63
    openTooltip Tooltip.js:337
    _openTooltip Tooltip.js:420
    fire Events.js:195
    _propagateEvent Events.js:311
    fire Events.js:204
    _propagateEvent Events.js:311
    fire Events.js:204
    _propagateEvent Events.js:311
    fire Events.js:204
    _fireDOMEvent Map.js:1452
    _handleDOMEvent Map.js:1401
    o DomEvent.js:108

If this approach looks right, the MultiPoint limitation in the GeoJSON docs and the GeometryCollection warning in GeoJsonDetail would need updating. Happy to do that here or in a follow-up.

Tested with

  • folium 0.20.0 (reproduction) and this branch off 03cb432
  • Leaflet 1.9.3, as pinned in folium/folium.py
  • Firefox 153.0.1 and Chrome 151 on Linux

Two tests fail on this branch, both of which also fail on clean main:

  • tests/test_map.py::test_icon_invalid_marker_colorsIcon.__init__ calls color.startswith("#") before validating the type, so color=42 raises AttributeError instead of emitting the expected UserWarning (folium/map.py:436). Unrelated to this change; happy to open a separate issue or PR.

  • tests/plugins/test_time_slider_choropleth.py::test_timedynamic_geo_jsongeodatasets not installed locally.

tests/test_features.py: 20 passed. tests/test_map.py and tests/plugins: 91 passed, 2 failed (both above).

Fixes #1520

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 python-visualization#1520
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.
@hansthen

hansthen commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

@nina-mir This looks like a promising and elegant approach. I must admit I do not grasp quite how this change solves the issue. Could you explain this a bit more (just for my curiosity)?

Interested to see the regression tests. I'd be happy to accept this here. Isn't this also an upstream problem? It looks like an issue in Leaflet itself as well.

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.

Tooltip and Popup don't work in GeoJson with MultiPoint geometry

2 participants