I was inspired by this post How to edit an existing layer using leaflet? I can click on an item to make it editable. But this does not "activate" the drawControl to allow me to click save or cancel, so I have not found out how I can catch an "edited" event to store the updated feature to my db?
Is there a way I can toggle the edit function for the drawControl to utilize the save/cancel after I manually made a layer editable?
onEachFeature: function (feature, layer) {
layer.on('click', function(e){
if(selectedFeature)
selectedFeature.editing.disable();
selectedFeature = e.target;
e.target.editing.enable();
});
As noted by TomazicM. drawnItems.addLayer(e.target);
need to go inside the onEachFeature function.
To make the save/cancel option to show up I faked a button click on the edit button. document.querySelector(".leaflet-draw-edit-edit").click();
To fake a click on cancel button document.querySelector("ul li:last-child a").click();
drawnItems.addLayer(e.target);
andvar drawControl = new L.Control.Draw({ …
?