Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用传单。绘图编辑激活_Javascript_Leaflet - Fatal编程技术网

Javascript 如何使用传单。绘图编辑激活

Javascript 如何使用传单。绘图编辑激活,javascript,leaflet,Javascript,Leaflet,我不确定我需要做什么才能使传单.draw的编辑功能发挥作用。我创建了一个形状,但“编辑”按钮在创建后仍保持灰色。据我所知,我的代码与ReadMe相同 // Initialise the FeatureGroup to store editable layers var drawnItems = new L.FeatureGroup(); map.addLayer(drawnItems); // Initialise the draw control and pass it the Featur

我不确定我需要做什么才能使传单.draw的编辑功能发挥作用。我创建了一个形状,但“编辑”按钮在创建后仍保持灰色。据我所知,我的代码与ReadMe相同

// Initialise the FeatureGroup to store editable layers
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);

// Initialise the draw control and pass it the FeatureGroup of editable layers
var drawControl = new L.Control.Draw({
edit: {
    featureGroup: drawnItems
},
draw:{
    rectangle: false,
    circle: false
}
});
map.addControl(drawControl);

// On Shape/Line/Marker completion
map.on('draw:created', function (e) {
var type = e.layerType,
    layer = e.layer;

if (type === 'marker') {
    // Do marker specific actions
}

// Do whatever else you need to. (save to db, add to map etc)
map.addLayer(layer);
});

// On Editing Completion
map.on('draw:edited', function (e) {
var layers = e.layers;
layers.eachLayer(function (layer) {
    //do whatever you want, most likely save back to db
});
});

我确保我已经设置了功能组,因为自述文件清楚地表明这是必需的,但我找不到关于它的任何其他内容。

我最终解决了这个问题。您需要更改提供代码中的代码,以将形状添加到
drawnItems
层,而不是添加到
map

// On Shape/Line/Marker completion
map.on('draw:created', function (e) {
var type = e.layerType, 
    layer = e.layer;

    if (type === 'marker') {
    // Do marker specific actions
    }

// Do whatever else you need to. (save to db, add to map etc)
    drawnItems.addLayer(layer) // previously map.addLayer(layer);
});