Giter Site home page Giter Site logo

Ability to cancel drawing about leaflet.draw HOT 7 CLOSED

leaflet avatar leaflet commented on August 20, 2024
Ability to cancel drawing

from leaflet.draw.

Comments (7)

Loykos avatar Loykos commented on August 20, 2024 9

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

from leaflet.draw.

jacobtoye avatar jacobtoye commented on August 20, 2024 3

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

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

// Start drawing
myPolylineDrawHandler.enable();

// Cancel drawing
myPolylineDrawHandler.disable();

from leaflet.draw.

BitaShamsafar avatar BitaShamsafar commented on August 20, 2024 1

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

from leaflet.draw.

georgecoltart avatar georgecoltart commented on August 20, 2024

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 :)

from leaflet.draw.

jacobtoye avatar jacobtoye commented on August 20, 2024

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

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

// Cancel drawing
myPolylineDrawHandler.disable();

from leaflet.draw.

georgecoltart avatar georgecoltart commented on August 20, 2024

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

from leaflet.draw.

mapping-mat avatar mapping-mat commented on August 20, 2024

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

from leaflet.draw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.