javascript - Identify when Leaflet Draw cancel button is clicked -
problem
i'm using leaflet draw application, , have 'remove' button active. remove button has 3 options:
- save
- cancel
- clear all
i want function foo()
called if user clicks save, however, want function bar()
called should click cancel.
solution
i know achieved giving id, , adding event listener, it's not clean think should be.
ideal solution
leaflet draw own methods detecting when buttons pressed seems me 1 level higher. example:
draw:deletestop
type of edit is. 1 of: remove triggered when user has finished removing shapes (remove mode) , saves.
this allows me call foo()
after user has selected any of 3 options, rendering have finished dealing remove button interaction.
i cannot find way in docs able listen leaflet draw firing event on individual buttons being pressed.
the handler cancel/disable function stored part of l.control.draw
instance. so, you can modify handler right after instantiate l.control.draw
object:
var mydrawcontrol = new l.control.draw(); mydrawcontrol._toolbars.edit.disable = function () { if (!this.enabled()) { /* if need right edit tool enabled, here right before return */ return; } this._activemode.handler.revertlayers(); /* if need when cancel button pressed , edits reverted, here. */ l.toolbar.prototype.disable.call(this); };
the source handler here , while works well, have careful future versions of leaflet.draw may change handler's functionality.
wiki
Comments
Post a Comment