Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to cancel drawing #34

Closed
jacobtoye opened this issue Oct 15, 2012 · 7 comments
Closed

Ability to cancel drawing #34

jacobtoye opened this issue Oct 15, 2012 · 7 comments
Labels
Milestone

Comments

@jacobtoye
Copy link
Member

Currently the user can press Esc to cancel drawing. Should also add a button that cancels as well. Could appear only when user has selected a drawing tool.

@georgecoltart
Copy link

I'm attempting to do this programmatically without using the L.Draw UI, is there a function that triggers the cancelling of the drawing?

I've been using this successfully to start the drawing: new L.Draw.Polyline(map, drawControl.options.polyline).enable();

I've tried clearing the target FeatureGroup but it seems there's nothing in there until the shape has been finished?

thanks :)

@jacobtoye
Copy link
Member Author

@georgecoltart All you need to do is disable the handler :)

// Start drawing
var myPolylineDrawHandler = new L.Draw.Polyline(map).enable();

// Cancel drawing
myPolylineDrawHandler.disable();

@georgecoltart
Copy link

Thanks but the handler seems to be undefined when I try cancel it? the first line works fine to activate the drawing mode though

    var polylineDrawHandler = new L.Draw.Polyline(map).enable();

    console.log('polylineDrawHandler: ' + polylineDrawHandler);

This traces as undefined in the console...

@jacobtoye
Copy link
Member Author

Ah sorry handler.enable() doesn't return this. Try:

var myPolylineDrawHandler = new L.Draw.Polyline(map);

// Start drawing
myPolylineDrawHandler.enable();

// Cancel drawing
myPolylineDrawHandler.disable();

@Loykos
Copy link

Loykos commented Jul 2, 2018

How can I cancel drawing if started by the Toolbar button? How can I get the drawHandler?

@BitaShamsafar
Copy link

BitaShamsafar commented Sep 23, 2019

try this
L.DomEvent.on(document.getElementById('abbruch'), 'click', this.disable, this);
put it in Toolbar.js inside one of functions

@mapping-mat
Copy link

this worked for me:
drawControl._toolbars.draw._activeMode.handler.disable()
given:
var drawControl = new L.Control.Draw({position: 'topleft'});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants