Snap interaction not working correctly with Circles in GeometryCollection
Describe the bug
These getType calls will return 'GeometryCollection', but the actual Geometry type is needed.
https://github.com/openlayers/openlayers/blob/1d25288271b15b6350cf0d22d9f621d85d0a1342/src/ol/interaction/Snap.js#L815-L815 https://github.com/openlayers/openlayers/blob/1d25288271b15b6350cf0d22d9f621d85d0a1342/src/ol/interaction/Snap.js#L838-L838 https://github.com/openlayers/openlayers/blob/1d25288271b15b6350cf0d22d9f621d85d0a1342/src/ol/interaction/Snap.js#L864-L864
Also with custom segmenters we can't assume the geometry type for the segments will match the geometries.
Should the segmenters return an object with the segments and geometry type? (would be a breaking change). Or allow both and wrap it in an object together with the type if an array is returned.
Hi, I’m Iqbal Hameed. I’d like to contribute and work on this issue. Could you please confirm if it’s available?
@IQBAL-HAMEED17 Sure! Which solution path do you have in mind?
Thank you for the clarification. From the code references in the issue, I see the problem clearly.
Inside Snap.js, the logic checks the geometry type directly with: segmentData.feature.getGeometry().getType()
But when a Circle is inside a GeometryCollection, getType() returns only "GeometryCollection", so the internal geometries (such as Circle) are never detected. Because of this, the Snap interaction does not generate the correct segments for Circles inside GeometryCollection.
My plan is:
- Reproduce the issue locally.
- Update the segment generation logic so that when the geometry is a GeometryCollection, I iterate through its child geometries and handle each according to its real type (e.g., Circle → approximate to segments).
- Ensure that Circle-specific snapping logic applies even when the Circle is nested.
- Test with different GeometryCollection structures to confirm snapping works correctly.
Please let me know if this approach aligns with what you expect.
@IQBAL-HAMEED17 Sounds reasonable, please go ahead!