[英]What function/event is fired by the “Cancel” button in leaflet.draw?
[英]Identify when Leaflet Draw cancel button is clicked
我正在使用傳單繪制我的應用程序,我有'刪除'按鈕激活。 刪除按鈕有三個選項:
我希望在用戶單擊Save時調用函數foo()
,但是,我希望在單擊Cancel時調用函數bar()
。
我知道這可以通過簡單地給它一個ID,並添加一個事件監聽器來實現,但它並不像我認為的那樣干凈。
Leaflet繪制了自己的方法,用於檢測按鈕何時被按下,但在我看來,它們只能在更高的級別上進行。 例如:
draw:deletestop
這是編輯的類型。 其中之一:刪除當用戶完成刪除形狀(刪除模式)並保存時觸發。- 傳單文件
這允許我在用戶選擇三個選項中的任何一個后調用foo()
,表示他們已經完成了處理刪除按鈕交互。
我無法在文檔中找到一種方法,能夠在按下的各個按鈕上偵聽傳單繪制觸發事件。
取消/禁用功能的處理程序存儲為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的未來版本。
您可以使用Leaflet.draw 0.4.14的最新版本
map.on('draw:toolbarclosed',function(){//在這里添加代碼});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.