2015-04-12 93 views
1

我不確定需要做什麼才能使leaflet.draw的編輯功能正常工作。我創建了一個形狀,但之後編輯按鈕保持灰色。就我所知,我的代碼與閱讀我的代碼相同。如何使用Leaflet.draw編輯激活

// 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 
}); 
}); 

我確信我已經設置爲自述使它很清楚,這是需要的功能組,但我無法找到任何關於它。

回答

2

我終於搞清楚了。您需要更改提供的代碼中的代碼,以將圖形添加到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); 
});