我使用featuresremoved事件讓所有的刪除的功能,然後我驗證它是否是一個「插入」狀態。 爲了防止在多次縮小時出現多次插入,我給該功能設置了一箇中間狀態。並在前端進行插入,將狀態再次改爲「插入」。 請注意,我一次只有一個編輯層。
var nuevas_features = null;
....
....
....
....
eventListeners: {
'loadstart': function(evt) {
nuevas_features = null;
},
'featuresremoved' : function(algunfeature) {
nuevas_features = null;
nuevas_features = new Array();
$(algunfeature.features).each(function(index, feature)
{
if(feature.state === 'Insert')
{
var feature_clonada = feature.clone();
feature_clonada.state = "transicion";
nuevas_features.push(feature_clonada);
}
});
},
'loadend': function(evt) {
$(nuevas_features).each(function(index, feature)
{
feature.state = "Insert";
editingLayer.addFeatures(feature);
});
console.log('end');
}
}
這裏是我目前使用的解決辦法:在層「loadstart」處理,去除所有的新特性,並在層「loadend」處理,重新添加所有新的特徵。在重新查詢db imho時,OpenLayers不應刪除具有INSERT狀態的功能。 – Hilo 2013-05-14 16:08:44
如何向開放層添加功能?這聽起來像是你正在用手繪製它們,而不是將它們添加到地圖中。 – 2013-05-15 23:16:33
新功能由用戶使用將圖層添加到圖層的OpenLayers繪圖控件繪製。 – Hilo 2013-05-17 02:58:52