0

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();

5
  • 1
    Code above is only a part of required code from the example you are referring to. What about the rest: drawnItems.addLayer(e.target); and var drawControl = new L.Control.Draw({ …?
    – TomazicM
    Commented Feb 18, 2020 at 7:56
  • Thanks, I thought it was something basic I did wrong. Adding drawnItems.addLayer(e.target); inside the click event made it work.
    – geogrow
    Commented Feb 18, 2020 at 8:01
  • 1
    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();
    – geogrow
    Commented Feb 18, 2020 at 12:23
  • 1
    Publish your complete solution as answer. It's easier to find if someone needs it and if it's marked as accepted.
    – TomazicM
    Commented Feb 18, 2020 at 12:43
  • Please publish you solution as answer to your own question, not as edit to the question.
    – TomazicM
    Commented Feb 18, 2020 at 13:52

1 Answer 1

0

The answer to the problem can be found here: https://github.com/Leaflet/Leaflet.draw/issues/129

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jun 28, 2023 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.