Leaflet / Leaflet.Editable

Make geometries editable in Leaflet.
http://leaflet.github.io/Leaflet.Editable/doc/api.html
559 stars 197 forks source link

Prevent Polygon Auto Complete #169

Open RyanMulready opened 6 years ago

RyanMulready commented 6 years ago

When drawing a polygon once at least three vertex exist the shape appears to close as the last drawn vertex and the first vertex have a line connecting the two. This behavior is confusing to the user as the drawing event is still on going but the shape appears to be "complete".

Is there any way to prevent this behavior?

tonyurso commented 5 years ago

Any updates on this?

RyanMulready commented 5 years ago

Just FYI I never did solve this @tonyurso and this project is pretty much dead.

Pentiado commented 5 years ago

The library is super minimalistic so drawing the polygon is actually... adding points to the polygon. What you're looking for is having a polyline becoming a polygon once a user clicks on the first vertex and it's dead simple to achieve:

map.editTools.startPolyline();

map.on('editable:vertex:click', (event) => {
      const { vertex: { latlngs }, latlng } = event;
      if (latlngs[0].lat === latlng.lat && latlngs[0].lng === latlng.lng) {
        map.editTools.stopDrawing();
        event.layer.remove();
        L.polygon(latlngs).addTo(map).enableEdit();
      }
    });