Currently, I allow users to edit a single feature at a time by moving it to the EditShapesLayer
in the EditOverlay
. Normally, you can click on the edge of the shape to add a vertex. However, in my app a single click while in edit mode will move the shape to the click location. So I need a different way to add that vertex in. Is there a built-in function to determine if a mouse click is on a shape’s edge or not?
Determining if user clicked on edge of shape
Hi Dan,
I think we don’t have an API to know whether the target point(clicked point) is on the shape’s edge.
But you can implement it like this:
A.
- Loop all line part of target shape, get distance from clicked point to each line part
- If any distance is smaller than a tolerance value you set, you think the clicked point is in this part
B.
- Buffer the point to a very small rectangle
- Adjust whether the rectangle intersect the shape but it’s not contained by it, if so it should be in the edge
Wish that’s helpful.
Regards,
Ethan