diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index 38ad4ab5c6..9c6e076c1f 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -234,6 +234,12 @@ class VectorSource extends Source { */ this.loadedExtentsRtree_ = new RBush(); + /** + * @type {number} + * @private + */ + this.loadingExtentsCount_ = 0; + /** * @private * @type {!Object>} @@ -901,7 +907,6 @@ class VectorSource extends Source { loadFeatures(extent, resolution, projection) { const loadedExtentsRtree = this.loadedExtentsRtree_; const extentsToLoad = this.strategy_(extent, resolution); - this.loading = false; for (let i = 0, ii = extentsToLoad.length; i < ii; ++i) { const extentToLoad = extentsToLoad[i]; const alreadyLoaded = loadedExtentsRtree.forEachInExtent( @@ -915,6 +920,7 @@ class VectorSource extends Source { } ); if (!alreadyLoaded) { + ++this.loadingExtentsCount_; this.dispatchEvent( new VectorSourceEvent(VectorEventType.FEATURESLOADSTART) ); @@ -924,6 +930,7 @@ class VectorSource extends Source { resolution, projection, function (features) { + --this.loadingExtentsCount_; this.dispatchEvent( new VectorSourceEvent( VectorEventType.FEATURESLOADEND, @@ -933,15 +940,17 @@ class VectorSource extends Source { ); }.bind(this), function () { + --this.loadingExtentsCount_; this.dispatchEvent( new VectorSourceEvent(VectorEventType.FEATURESLOADERROR) ); }.bind(this) ); loadedExtentsRtree.insert(extentToLoad, {extent: extentToLoad.slice()}); - this.loading = this.loader_ !== VOID; } } + this.loading = + this.loader_ === VOID ? false : this.loadingExtentsCount_ > 0; } refresh() { diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js index 0f71bd84f1..4546c2f44d 100644 --- a/test/spec/ol/map.test.js +++ b/test/spec/ol/map.test.js @@ -28,7 +28,9 @@ import { transform, useGeographic, } from '../../../src/ol/proj.js'; +import {createXYZ} from '../../../src/ol/tilegrid.js'; import {defaults as defaultInteractions} from '../../../src/ol/interaction.js'; +import {tile as tileStrategy} from '../../../src/ol/loadingstrategy.js'; describe('ol.Map', function () { describe('constructor', function () { @@ -226,6 +228,13 @@ describe('ol.Map', function () { format: new GeoJSON(), }), }), + new VectorLayer({ + source: new VectorSource({ + url: 'spec/ol/data/point.json', + format: new GeoJSON(), + strategy: tileStrategy(createXYZ()), + }), + }), new VectorLayer({ source: new VectorSource({ features: [new Feature(new Point([0, 0]))],