From 9bfb0c1b9d4d5025b23aabcf09d4e2c9c5bb1446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 12 Feb 2022 23:55:59 +0100 Subject: [PATCH 1/2] Test VectorSource isEmtpty without spatial index --- test/browser/spec/ol/source/vector.test.js | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/browser/spec/ol/source/vector.test.js b/test/browser/spec/ol/source/vector.test.js index 1f992d0e31..94beac641f 100644 --- a/test/browser/spec/ol/source/vector.test.js +++ b/test/browser/spec/ol/source/vector.test.js @@ -50,6 +50,34 @@ describe('ol.source.Vector', function () { it('returns true', function () { expect(vectorSource.isEmpty()).to.be(true); }); + it('returns true without spatial index', function () { + const source = new VectorSource({ + useSpatialIndex: false, + }); + expect(source.isEmpty()).to.be(true); + }); + it('returns false with geometry', function () { + vectorSource.addFeature(new Feature(new Point([0, 0]))); + expect(vectorSource.isEmpty()).to.be(false); + }); + it('returns false without spatial index and geometry', function () { + const source = new VectorSource({ + useSpatialIndex: false, + }); + source.addFeature(new Feature(new Point([0, 0]))); + expect(source.isEmpty()).to.be(false); + }); + it('returns false with null geometry', function () { + vectorSource.addFeature(new Feature()); + expect(vectorSource.isEmpty()).to.be(false); + }); + it('returns false without spatial index and null geometry', function () { + const source = new VectorSource({ + useSpatialIndex: false, + }); + source.addFeature(new Feature()); + expect(source.isEmpty()).to.be(false); + }); }); describe('#addFeature', function () { From e2c9f62cc683b1b0df9add2d9e6d239876c0308a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 13 Feb 2022 00:08:24 +0100 Subject: [PATCH 2/2] Fix VectorSource isEmpty without spatial index --- src/ol/source/Vector.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index aed90d7369..c367084f21 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -941,7 +941,15 @@ class VectorSource extends Source { * @return {boolean} Is empty. */ isEmpty() { - return this.featuresRtree_.isEmpty() && isEmpty(this.nullGeometryFeatures_); + if (this.featuresRtree_) { + return ( + this.featuresRtree_.isEmpty() && isEmpty(this.nullGeometryFeatures_) + ); + } + if (this.featuresCollection_) { + return this.featuresCollection_.getLength() === 0; + } + return true; } /**