Leaflet.Editable icon indicating copy to clipboard operation
Leaflet.Editable copied to clipboard

How to draw a straight line

Open abdelba opened this issue 8 years ago • 2 comments

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.

abdelba avatar Aug 03 '16 12:08 abdelba

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.

  1. You can draw a straight lines.
  2. You can edit straight lines by dragging the line ends.
  3. You cannot create lines with more than 2 vertices.

SuberFu avatar Aug 03 '16 14:08 SuberFu

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.

abdelba avatar Aug 05 '16 13:08 abdelba