Issue 1520: Propagate feature to child layers of multi-geometries - #2263
Draft
nina-mir wants to merge 2 commits into
Draft
Issue 1520: Propagate feature to child layers of multi-geometries#2263nina-mir wants to merge 2 commits into
nina-mir wants to merge 2 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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.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.
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