openlayers icon indicating copy to clipboard operation
openlayers copied to clipboard

Snap interaction not working correctly with Circles in GeometryCollection

Open MoonE opened this issue 3 months ago • 4 comments

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.

MoonE avatar Sep 21 '25 15:09 MoonE

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 avatar Dec 05 '25 13:12 IQBAL-HAMEED17

@IQBAL-HAMEED17 Sure! Which solution path do you have in mind?

ahocevar avatar Dec 05 '25 14:12 ahocevar

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:

  1. Reproduce the issue locally.
  2. 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).
  3. Ensure that Circle-specific snapping logic applies even when the Circle is nested.
  4. Test with different GeometryCollection structures to confirm snapping works correctly.

Please let me know if this approach aligns with what you expect.

IQBAL-HAMEED17 avatar Dec 05 '25 15:12 IQBAL-HAMEED17

@IQBAL-HAMEED17 Sounds reasonable, please go ahead!

ahocevar avatar Dec 05 '25 17:12 ahocevar