I have spend more than 4 hours trying to figure out how I can do this. I use Leaflet and Leaflet Draw in order to draw news features on my map.
Now I want to be able to edit features of an existing WFS layer (coming from geoserver).
I have searched a lot all around internet and I can not find a clear example of how to make my WFS layer editable.
This is what I do based on the example from here:
// intialize the drawItems and add it to the map
var drawnItems = new L.FeatureGroup();
map_add.addLayer(drawnItems);
// initialize the controls (only editing) and add it to the map
var drawControl = new L.Control.Draw({
draw: {
position: 'topleft'
},
edit: {
featureGroup: drawnItems,
edit: true
}
}
});
map_add.addControl(drawControl);
url_string = "thats my url"
// make wfs request and add the layer in the drawItems
var geojson = $.ajax({
type: "GET",
dataType: "json",
url: url_string,
success: function (response) {
drawnItems.addLayer(L.geoJson(response));
}
});
The layer is displayed on the map. But when I click the edit button (of the leaflet draw plugin) I get a:
Cannot read property 'enable' of undefined
What am I doing wrong? Please advise! If I follow the example in the link I provided it works. But the guy there he uses data inline with his code. I need to use the layer from the WFS request.