leaflet-geoman
leaflet-geoman copied to clipboard
Disable finish drawing when existing vertex is clicked
When user is drawing a line and existing vertex is clicked, the drawing is finished. How can I disable this behaviour to finish drawing only when "Finish" button is clicked?
Currently this is not built in, but we will think about adding it.
You can use following code:
const createMarkerProto = L.PM.Draw.Line.prototype._createMarker;
const setTooltipTextProto = L.PM.Draw.Line.prototype._setTooltipText;
L.PM.Draw.Line.include({
_createMarker: function(latlng){
const marker = createMarkerProto.call(this, latlng);
marker.off('click', this._finishShape, this);
return marker;
},
_setTooltipText: function() {
setTooltipTextProto.call(this);
const { length } = this._layer.getLatLngs().flat();
if (length > 1) {
this._hintMarker.setTooltipContent('Click finish in the Toolbar to create the Line');
}
},
});
map.pm.Draw.Line = new L.PM.Draw.Line(map);
@Falke-Design thank you, this is great improvement, but with this modification it's still possible to finish drawing when user clicks or double clicks the existing vertex. I guess it's because of this code, and perhaps it's not so easy to modify.