【问题标题】:OpenLayers removes/destroys new features when zooming outOpenLayers 在缩小时删除/破坏新功能
【发布时间】:2013-05-13 21:32:37
【问题描述】:

我有一个 OpenLayers.Layer.Vector 层,允许用户创建、修改和删除要素和要素属性。当他们点击“保存更改”按钮时,更改将被保存。如果用户创建了一个新要素,然后将地图缩小,这会导致 OpenLayers 从图层中删除所有要素,只添加保存到 GeoServer 数据库的要素。我已经尝试挂在新创建的特征上并将它们添加回“loadend”事件的图层,但 OpenLayers 已经破坏了新特征的几何形状,因此它们没有用。缩小时如何防止 OpenLayers 破坏新功能?

【问题讨论】:

  • 这是我目前使用的解决方法:在“loadstart”层处理程序中,删除所有新功能,在“loadend”层处理程序中,重新添加所有新功能。重新查询数据库 imho 时,OpenLayers 不应删除状态为 INSERT 的功能。
  • 如何向 openlayers 添加功能?听起来您是在手动绘制它们,而不是将它们添加到地图中。
  • 新功能由用户使用 OpenLayers 绘图控件绘制,将它们添加到图层中。
  • 我不知道为什么 OpenLayers 会删除您的新功能,它并不是开箱即用的。请参考openlayers.org/dev/examples/draw-feature.html
  • 如果您查看 OpenLayers.Strategy.BBOX 的代码,您会发现它确实“开箱即用”。当您缩小时,将使用新的 BBOX 重新查询图层并调用 OpenLayers.Strategy.BBOX.merge() 调用 this.layer.destroyFeatures() 从而删除/销毁所有当前功能并仅添加保存到数据库中的那些功能.

标签: openlayers zooming geoserver removeall missing-features


【解决方案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');

}

}

【讨论】:

    猜你喜欢
    • 2021-01-17
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多