Issue 1520: Propagate feature to child layers of multi-geometries - #2263
Issue 1520: Propagate feature to child layers of multi-geometries#2263nina-mir wants to merge 3 commits into
Conversation
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.
|
@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. |
|
Happy to explain! The chain begins with the The catch is what
So the two ends disagree: The patch copies the feature down onto the children inside It also explains why On upstream: I tested it outside folium via plain Leaflet from a CDN, the reporter's I couldn't find an existing Leaflet issue for this. Happy to open one with the repro if Regression tests are next: |
|
Test added. It fails on Two notes on how it's written:
|
Leaflet's
geometryToLayerreturns aFeatureGroupforMultiPoint, andaddDataassignsfeatureto that group only. Tooltips resolve their source to the layer that fired the event, which is a child marker with nofeature, so the content function throws before rendering. This copies the feature onto child layers inonEachFeature, descending recursively so that nested groups — aGeometryCollectioncontaining aMultiPoint— are also covered.Verified in Firefox/Chrome against the reporter's snippet and a matrix of all eight geometry types.
MultiLineStringandMultiPolygonare unaffected, since Leaflet flattens those into a single layer rather than a group.FeatureGroupFeatureGroupGeometryCollectioncontainingMultiPointFeatureGroupConsole error before the fix
If this approach looks right, the
MultiPointlimitation in the GeoJSON docs and theGeometryCollectionwarning inGeoJsonDetailwould need updating. Happy to do that here or in a follow-up.Tested with
0.20.0(reproduction) and this branch off03cb432folium/folium.pyTwo tests fail on this branch, both of which also fail on clean
main:tests/test_map.py::test_icon_invalid_marker_colors—Icon.__init__callscolor.startswith("#")before validating the type, socolor=42raisesAttributeErrorinstead of emitting the expectedUserWarning(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_json—geodatasetsnot installed locally.tests/test_features.py: 20 passed.tests/test_map.pyandtests/plugins: 91 passed, 2 failed (both above).Fixes #1520