删除一系列功能(OpenLayers 4) [英] Remove array of features (OpenLayers 4)

查看:121
本文介绍了删除一系列功能(OpenLayers 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在尝试从OpenLayers 4映射中删除一系列功能. 我不想清除源代码中的所有功能.向阵列中添加了一些选定的功能.

Am trying to remove an array of features from OpenLayers 4 map. I don't want to clear all features in the source. Added few selected features to an array.

当前,正在迭代数组并使用它. source.removeFeature(array[index]);

Currently, am iterating array and using this. source.removeFeature(array[index]);

不是多次循环,有什么方法可以一次删除数组中的功能吗?

Instead of looping many times is there is any way to remove features in an array at one time?

注意:我不想删除源代码中的所有功能,而只需删除 我添加到阵列中的功能

Note: I don't want to remove all features in the source, but just the features which I have added to my array

代码:

var docketSource = new ol.source.Vector({
    url: dataUrl,
    format: new ol.format.TopoJSON()
});
var redFeatures = [];
function removeRedFeature(redFeatures) {
   for (var i = 0; i < redFeatures.length; i++) {
       docketSource.removeFeature( redFeatures[i] );
   }
}

推荐答案

假设您的sourceol.source.Vector,则可以执行以下操作来执行clear():

Assuming your source is an ol.source.Vector you can execute clear() by doing:

source.clear()

我对您的要求有些困惑,但是您提到了某些功能".也许这就是您所追求的?

I'm a little confused with what you're asking, but you've mentioned "selected features". Perhaps this is what you're after?

var select = new ol.interaction.Select();
select.getFeatures().forEach(function(feature){
   docketSource.removeFeature(feature);
});

请参见 http://openlayers.org/zh/v3.0.0/apidoc/ol.source.Vector.html#clear 了解更多信息.

更新:在 OL 2.13.1 中有一个removeFeatures函数.

removeFeatures:功能(功能,选项)

removeFeatures: function(features, options)

从图层中删除要素.这会删除所有绘制的要素,并将其从图层的控件中删除.对于每个功能,将触发beforefeatureremoved和featureremoved事件.删除所有功能后,将触发featuresremoved事件.要抑制事件触发,请使用silent选项.

请参阅: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆