From a01893b27547da2c72e5203fa99cdec106cef669 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 31 Mar 2021 18:17:04 +0200 Subject: [PATCH] VectorSource#getFeatures() consistently returns a new array --- src/ol/source/Vector.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index e686c8f335..6b68b481db 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -653,14 +653,15 @@ class VectorSource extends Source { } /** - * Get all features on the source in random order. + * Get all snapshot of the features currently on the source in random order. The returned array + * is a copy, the features are references to the features in the source. * @return {Array>} Features. * @api */ getFeatures() { let features; if (this.featuresCollection_) { - features = this.featuresCollection_.getArray(); + features = this.featuresCollection_.getArray().slice(0); } else if (this.featuresRtree_) { features = this.featuresRtree_.getAll(); if (!isEmpty(this.nullGeometryFeatures_)) { @@ -700,7 +701,7 @@ class VectorSource extends Source { if (this.featuresRtree_) { return this.featuresRtree_.getInExtent(extent); } else if (this.featuresCollection_) { - return this.featuresCollection_.getArray(); + return this.featuresCollection_.getArray().slice(0); } else { return []; }