1

I set up a custom button to initiate drawing as per How to click a button and start a new polygon without using the Leaflet.draw UI and How to initiate the draw function without toolbar?. However, once someone clicks on this custom button, I can't figure out how to imitate the behaviour of the Cancel button so that I can have something like

<input type="button" onclick="stopEdits()" value="Click to Stop Drawing">

function stopEdits() {
    //Cancel Drawing
}
Community
  • 1
  • 1
raphael
  • 2,762
  • 5
  • 26
  • 55

1 Answers1

2

So this was resolved by the following code, drawer.disable() cancels the marker placement.

var drawer = new L.Draw.Marker(map, drawControl.options.marker);

function startDrawing() {

    drawer.enable();
}

function stopDrawing() {
    drawer.disable()
}

The issue I had had was that I was previously doing too much in the same line:

var drawer = new L.Draw.Marker(map, drawControl.options.marker).enable();
raphael
  • 2,762
  • 5
  • 26
  • 55