How to allow only one feature/polygon to be edited at a time with Leaflet?

后端 未结 1 987
轻奢々
轻奢々 2021-02-06 10:54

It\'s been days I\'m trying to solve my problem.

I have a polygon layer from a GeoJSON. I want to edit my polygons with the click event. When I click on a polygon it bec

1条回答
  •  长情又很酷
    2021-02-06 11:10

    I think you are close. In your onEachFeature function you should store the feature that was clicked so you can enable/disable editing in the click handler.

    var selectedFeature = null;
    //edit the targeted polygon
    function onEachFeature (feature, layer) {
         editableLayers.addLayer(layer);
         layer.on('click', function(e){
              if(selectedFeature)
                   selectedFeature.editing.disable();
              selectedFeature = e.target;
              e.target.editing.enable();
         });
    }
    

    0 讨论(0)
提交回复
热议问题