問題描述
對于任何使用過傳單或傳單.draw 插件的人:
For anyone experienced with leaflet or leaflet.draw plugin:
我想在不使用 leaflet.draw
的工具欄的情況下開始繪制多邊形.我已經設法通過在線搜索(不在主文檔中)找到允許在不使用工具欄(layer.editing.enable();
)的情況下進行編輯的屬性.如果沒有工具欄按鈕,我似乎無法找到如何開始繪制多邊形.任何幫助將不勝感激!
I want to initiate drawing a polygon without using the toolbar from leaflet.draw
. I've managed to find the property that allows editing without using the toolbar (layer.editing.enable();
) by searching online (it's not in the main documentation). I can't seem to find how to begin drawing a polygon without the toolbar button. Any help would be much appreciated!
謝謝你:)
推薦答案
這個簡單的代碼對我有用:
This simple code works for me:
new L.Draw.Polyline(map, drawControl.options.polyline).enable();
只需將其放入自定義按鈕的 onclick 處理程序(或任何您想要的位置).
Just put it into the onclick handler of your custom button (or wherever you want).
變量 map
和 drawControl
是對您的傳單地圖和繪圖控件的引用.
The variables map
and drawControl
are references to your leaflet map and draw control.
深入研究源代碼 (leaflet.draw-src.js),您可以找到繪制其他元素以及編輯或刪除它們的函數.
Diving into the source code (leaflet.draw-src.js) you can find the functions to draw the other elements and to edit or delete them.
new L.Draw.Polygon(map, drawControl.options.polygon).enable()
new L.Draw.Rectangle(map, drawControl.options.rectangle).enable()
new L.Draw.Circle(map, drawControl.options.circle).enable()
new L.Draw.Marker(map, drawControl.options.marker).enable()
new L.EditToolbar.Edit(map, {
featureGroup: drawControl.options.featureGroup,
selectedPathOptions: drawControl.options.edit.selectedPathOptions
})
new L.EditToolbar.Delete(map, {
featureGroup: drawControl.options.featureGroup
})
我希望這對你也有用.
L.EditToolbar.Edit
和 L.EditToolbar.Delete
類公開了以下有用的方法:
The L.EditToolbar.Edit
and L.EditToolbar.Delete
classes expose the following useful methods:
- enable():啟動編輯/刪除模式
- disable():返回標準模式
- save():保存更改(觸發 draw:edited/draw:deleted 事件)
- revertLayers():撤消更改
這篇關于Leaflet.draw 映射:如何在沒有工具欄的情況下啟動繪圖功能?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!