Leaflet.Editable
Leaflet.Editable copied to clipboard
How to draw a straight line
I'm working on a gardening app for which I would like to be able to draw straight lines. The question is in two parts I think
- How to disable drawing after the creation of the second point ?
- How to disable adding a new point
Thanks.
I would guess you subscribe to editable:drawing:clicked
and editable:drawing:click
. clicked
happens after any internal actions. click
before internal action and can be cancelled.
For case 1, use the clicked
. Check if layer
has two points, is so, commit
that drawing to end the draw operation.
For case 2, use the editable:drawing:click
(I think that doesn't fire if you click on a vertex, which triggers editable:vertex:click
event). Same as above, except cancel the event.
Finally, set the skipMiddleMarker
to true.
This should get you the following.
- You can draw a straight lines.
- You can edit straight lines by dragging the line ends.
- You cannot create lines with more than 2 vertices.
Thank you for your answer, I managed to forbid adding more than two points via the editable:drawing:clicked
event. However, I cannot use skipMiddleMarkers
option because it's global for all geometries on the map and I need middle markers on polygons.