-1

Enable editing to layers drown using geojson

 var drawnItems = new L.FeatureGroup();
 map.addLayer(drawnItems);

Json data

    $.getJSON("js/draw/neighborhoods.json",function(hoodData){
     alert("this is editableLayers");
     var i = 0;
    var geojsonlayer = L.geoJson(hoodData,
    {
           onEachFeature: function (feature, layer) {
                alert(feature.properties.prop0);
                var myLayer = layer;
            drawnItems.addLayer(myLayer);

            }
    });
    map.addLayer(drawnItems);
    });

Adding control

    //draw control
    var drawControl = new L.Control.Draw({
        draw: false,
        edit: {
            featureGroup: drawnItems,
            remove: false,
            edit: true
       }
    });

    map.addControl(drawControl);
    map.on('draw:edited', function (e) {
    var layers = e.layers;
    layers.eachLayer(function (layer) {
        console.log(layer)
    });
});

Using this code i am able to draw the layers but unable to edit it. I am using leaflet.draw lib.

Pavan
  • 300
  • 3
  • 16

1 Answers1

0

If you could set up a JSFiddle with some sample data, I can take a closer look at the process you have set up.

Ideally, the geojson data would be available prior to adding to the control and adding to the map. Since this is asynchronous, you should have the control and layer added to the map after each update from your ajax/getJSON closure. Sort of like cleaning the workspace each time you have new data to edit.

Jon West
  • 27
  • 2