2017-05-18 36 views

回答

2

您只需將您的多邊形(或任何您想要編輯的其他圖層)添加到您傳遞到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

相關問題