Remove Array Of Features (openlayers 4)
Solution 1:
Your solution is one solution but you can also use docketSource.getFeaturesCollection()
that returns a ol.Collection
of ol.Feature
s. Then, you can manipulate the returned collection and use the function remove
So, you could do docketSource.getFeaturesCollection().remove(yourfeature);
However, if you need to loop through the collection, you will use forEach
method of the collection and it would be similar to your solution.
Look at ol.Collection
methods to see if they could fit better with your purpose.
Solution 2:
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);
});
See http://openlayers.org/en/v3.0.0/apidoc/ol.source.Vector.html#clear for more information.
UPDATE: There is a removeFeatures
function in OL 2.13.1.
removeFeatures: function(features, options)
Remove features from the layer. This erases any drawn features and removes them from the layer’s control. The beforefeatureremoved and featureremoved events will be triggered for each feature. The featuresremoved event will be triggered after all features have been removed. To suppress event triggering, use the silent option.
Solution 3:
removeFeature is the only API function to remove some features from an ol.source.Vector . (See https://github.com/openlayers/openlayers/blob/v4.6.5/src/ol/source/vector.js )
If you have problems with lots of events fired or something like that, you could extend the ol.source.Vector class and implement a removeFeatures function, for example modifying the clear function or merging clear with removeFeature.
Post a Comment for "Remove Array Of Features (openlayers 4)"