I'm using Leaflet Draw to let users draw a polyline in a map in order to measure sections. First step is to use Leaflet.Draw to let users draw the line. Leaflet.Draw includes a delete and edit button. These buttons are, however not working.
I've (re)used working code from other projects to create the draw control and pass it a FeatureGroup and editable layers.
// My draw Toolbar
var drawnItems = new L.FeatureGroup()
map.addLayer(drawnItems)
var drawControl = new L.Control.Draw({
draw:{polygon: false,
marker: false,
circlemarker: false,
rectangle: false,
circle: false,
},
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (e) {
var layer = e.layer;
map.addLayer(layer);
});
Seems like I'm linking the feature group correctly, but for some reason the delete and edit are not working :(
I'm using Leaflet Draw to let users draw a polyline in a map in order to measure sections. First step is to use Leaflet.Draw to let users draw the line. Leaflet.Draw includes a delete and edit button. These buttons are, however not working.
I've (re)used working code from other projects to create the draw control and pass it a FeatureGroup and editable layers.
// My draw Toolbar
var drawnItems = new L.FeatureGroup()
map.addLayer(drawnItems)
var drawControl = new L.Control.Draw({
draw:{polygon: false,
marker: false,
circlemarker: false,
rectangle: false,
circle: false,
},
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (e) {
var layer = e.layer;
map.addLayer(layer);
});
Seems like I'm linking the feature group correctly, but for some reason the delete and edit are not working :(
Share Improve this question asked Apr 5, 2019 at 8:49 Kaz VermeerKaz Vermeer 1451 silver badge10 bronze badges1 Answer
Reset to default 5You're adding the drawn items to map
but they should be added to the layer pointed by edit.featureGroup
if you want to edit them, i.e drawnItems
:
map.on(L.Draw.Event.CREATED, function (e) {
var layer = e.layer;
drawnItems.addLayer(layer);
});
Here's a demo https://jsfiddle/4g5u071r/