2013-05-13 103 views
0

時破壞新功能我有一個OpenLayers.Layer.Vector層,我允許用戶創建,修改和刪除功能和功能屬性。這些更改在點擊「保存更改」按鈕時被保存。如果用戶創建了一個新的功能,那麼縮放地圖出的方式,這將導致的OpenLayers從該層中除去所有功能,且只能在保存到GeoServer的數據庫功能添加。我曾嘗試掛到新創建的功能和增加他們回到層對「loadend」事件,但一直的OpenLayers破壞的新特徵的幾何形狀,使他們也沒用。如何防止OpenLayers在縮小時破壞新功能?的OpenLayers刪除/縮小

+0

這裏是我目前使用的解決辦法:在層「loadstart」處理,去除所有的新特性,並在層「loadend」處理,重新添加所有新的特徵。在重新查詢db imho時,OpenLayers不應刪除具有INSERT狀態的功能。 – Hilo 2013-05-14 16:08:44

+0

如何向開放層添加功能?這聽起來像是你正在用手繪製它們,而不是將它們添加到地圖中。 – 2013-05-15 23:16:33

+0

新功能由用戶使用將圖層添加到圖層的OpenLayers繪圖控件繪製。 – Hilo 2013-05-17 02:58:52

回答

-1

我使用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'); 

} 

}