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:

  1. save
  2. cancel
  3. clear all

i want function foo() called if user clicks save, however, want function bar() called should click cancel.

live demo

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.

- leaflet docs

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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -