Prevent Polygon Auto Complete
RyanMulready opened this issue · 3 comments
RyanMulready commented
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
Any updates on this?
RyanMulready commented
Just FYI I never did solve this @tonyurso and this project is pretty much dead.
Pentiado commented
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();
}
});