admin管理员组文章数量:1406937
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/
本文标签: javascriptLeafletDraw edit and delete button not workingStack Overflow
版权声明:本文标题:javascript - Leaflet.Draw edit and delete button not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744974455a2635432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论