Merge pull request #13373 from MoonE/vector-source-is-empty
Fix VectorSource isEmpty without spatial index
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user