Skip to content

fix: remove MultiGeometry features from the map in removeFeature#1725

Open
jamesarich wants to merge 1 commit into
googlemaps:mainfrom
jamesarich:fix/multigeometry-remove-feature
Open

fix: remove MultiGeometry features from the map in removeFeature#1725
jamesarich wants to merge 1 commit into
googlemaps:mainfrom
jamesarich:fix/multigeometry-remove-feature

Conversation

@jamesarich

@jamesarich jamesarich commented Jul 16, 2026

Copy link
Copy Markdown

Fixes #1722 🦕

MapViewRenderer.addFeature rendered MultiGeometry members by recursing with addFeature(feature.copy(geometry = member)), so the created map objects were keyed in the renderedFeatures IdentityHashMap by those intermediate copies rather than by the caller's feature. removeFeature(feature) then found no entry and silently removed nothing — toggling a layer containing MultiPolygon/MultiLineString/GeometryCollection features stranded their polygons, polylines, and markers on the map, and re-adding duplicated them. The deprecated GeoJsonLayer/KmlLayer bridges hit the same path via removeLayerFromMap().

Change: render nested geometries through a private addGeometry(geometry, feature, mapObjects) recursion that accumulates every created map object into the original feature's entry, so removeFeature works for any geometry shape. Pure refactor of the dispatch — per-geometry rendering logic is unchanged.

Tests: two new unit tests in MapViewRendererTestremoveFeature on a MultiPolygon feature removes both rendered polygons, and an add/remove/add/remove cycle leaves nothing behind (previously it leaked and duplicated). Full :data:testDebugUnitTest suite passes.


Developed with AI assistance (Claude Code); the analysis, fix, and tests were reviewed and run locally by the author before submission.

addFeature rendered MultiGeometry members by recursing with
feature.copy(geometry = member), so the created map objects were keyed in
the IdentityHashMap by those intermediate copies rather than by the
caller's feature. removeFeature(feature) then found no entry and silently
removed nothing: toggling a layer containing MultiPolygon/MultiLineString/
GeometryCollection features left their polygons, polylines, and markers
stranded on the map, and re-adding the layer duplicated them.

Render nested geometries through a private addGeometry(geometry, feature,
mapObjects) recursion instead, accumulating every created map object into
the original feature's entry so removeFeature works for any geometry.
@google-cla

google-cla Bot commented Jul 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

removeFeature() silently fails for MultiGeometry features (objects stranded on map, duplicated on re-add)

2 participants