leaflet-geoman icon indicating copy to clipboard operation
leaflet-geoman copied to clipboard

Disable finish drawing when existing vertex is clicked

Open AndrejGajdos opened this issue 1 year ago β€’ 2 comments

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?

AndrejGajdos avatar Aug 23 '23 03:08 AndrejGajdos

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 avatar Aug 23 '23 18:08 Falke-Design

@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.

geoman-click-existing-vertex

AndrejGajdos avatar Aug 24 '23 03:08 AndrejGajdos