Determine when the elevator cancel button is pressed.

Problem

I use a leaflet for my application, and the delete button is active for me. The delete button has three options:

  • Save
  • Cancel
  • Clear All

I want the function to be foo()called if the user clicks Save, however I want the function to be bar()called if they click Cancel.

Live demo

Decision

I know that this could be achieved simply by giving it an identifier and adding an event listener, but this is not as clean as I think it should be.

The perfect solution

The flyer uses its own methods for determining button presses, but it seems to me that they only do this one level higher. For instance:

draw:deletestop . : , ( ) .

-

foo() , , , .

, , .

+4
1

/ L.Control.Draw. , L.Control.Draw:

var myDrawControl = new L.Control.Draw();

myDrawControl._toolbars.edit.disable =  function () {
  if (!this.enabled()) {
    /* If you need to do something right as the
       edit tool is enabled, do it here right
       before the return */
    return;
  }

  this._activeMode.handler.revertLayers();
  /* If you need to do something when the
     cancel button is pressed and the edits
     are reverted, do it here. */
  L.Toolbar.prototype.disable.call(this);
};

, , Leaflet.Draw, .

+2

Source: https://habr.com/ru/post/1684296/


All Articles