JamesLMilner / terra-draw

A library for drawing on maps that supports Mapbox, MapLibre, Google Maps, OpenLayers and Leaflet out the box
https://terradraw.io
MIT License
447 stars 50 forks source link

[Bug] Select should choose Point and LineString over Polygon #268

Closed ScottEAdams closed 1 week ago

ScottEAdams commented 2 months ago

Describe the bug If you draw some points and then draw a polygon over those points (or vice versa), it is impossible to then select the points.

Terra Draw npm version alpha.68

To Reproduce Steps to reproduce the behavior:

  1. Go to terradraw.io
  2. Draw some points and a polygon over the top
  3. Try to select the points

Expected behavior I would expect that when clicking exactly on a point that it is the point that is selected. Similar for linestring.

Screenshots scrnli_03_07_2024_03-40-49.webm

ScottEAdams commented 2 months ago

I did a little playing around and although not perfect, I think an improvement is to check the type of features in featuresAtMouseEvent in select.mode.ts and prioritise Point then LineString then Polygon.

JamesLMilner commented 2 months ago

Hey @ScottEAdams thanks for raising this. I think you are right here in that the points should be selectable as they are layered on top of (z-indexed) above the polygon. I think I know what the problem is which is basically when we loop through the closest geometries, if the click is inside the polygon it always gets considered the 'closest' geometry. I will eventually look at fixing this when I get a moment. Let me know if you have any questions.

JamesLMilner commented 1 week ago

This is fixed in the main branch and will come out in the next release!