0
有沒有辦法使用Leaflet draw插件以編程方式添加多邊形? https://github.com/Leaflet/Leaflet.draw在小冊子中以編程方式添加多邊形L.Draw插件
例如:點擊一個按鈕並添加一個可以被插件編輯的正方形。
謝謝!
有沒有辦法使用Leaflet draw插件以編程方式添加多邊形? https://github.com/Leaflet/Leaflet.draw在小冊子中以編程方式添加多邊形L.Draw插件
例如:點擊一個按鈕並添加一個可以被插件編輯的正方形。
謝謝!
您只需將您的多邊形(或任何您想要編輯的其他圖層)添加到您傳遞到L.Control.Draw
控件的edit.featureGroup
選項的功能組。
var editableLayers = L.featureGroup().addTo(map);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: editableLayers
}
});
// Add a new editable rectangle when clicking on the button.
button.addEventListener('click', function (event) {
event.preventDefault();
L.rectangle([
getRandomLatLng(),
getRandomLatLng()
]).addTo(editableLayers); // Add to editableLayers instead of directly to map.
});
一切是在該特徵組可以在以後通過點擊「編輯層」按鈕(如果啓用該功能)進行編輯。
演示:http://playground-leaflet.rhcloud.com/yili/1/edit?html,output