Merge pull request #11941 from ahocevar/strategy-loading

Fix loading flag for vector loading strategies
This commit is contained in:
Andreas Hocevar
2021-01-23 23:12:50 +01:00
committed by GitHub
2 changed files with 20 additions and 2 deletions
+11 -2
View File
@@ -234,6 +234,12 @@ class VectorSource extends Source {
*/ */
this.loadedExtentsRtree_ = new RBush(); this.loadedExtentsRtree_ = new RBush();
/**
* @type {number}
* @private
*/
this.loadingExtentsCount_ = 0;
/** /**
* @private * @private
* @type {!Object<string, import("../Feature.js").default<Geometry>>} * @type {!Object<string, import("../Feature.js").default<Geometry>>}
@@ -901,7 +907,6 @@ class VectorSource extends Source {
loadFeatures(extent, resolution, projection) { loadFeatures(extent, resolution, projection) {
const loadedExtentsRtree = this.loadedExtentsRtree_; const loadedExtentsRtree = this.loadedExtentsRtree_;
const extentsToLoad = this.strategy_(extent, resolution); const extentsToLoad = this.strategy_(extent, resolution);
this.loading = false;
for (let i = 0, ii = extentsToLoad.length; i < ii; ++i) { for (let i = 0, ii = extentsToLoad.length; i < ii; ++i) {
const extentToLoad = extentsToLoad[i]; const extentToLoad = extentsToLoad[i];
const alreadyLoaded = loadedExtentsRtree.forEachInExtent( const alreadyLoaded = loadedExtentsRtree.forEachInExtent(
@@ -915,6 +920,7 @@ class VectorSource extends Source {
} }
); );
if (!alreadyLoaded) { if (!alreadyLoaded) {
++this.loadingExtentsCount_;
this.dispatchEvent( this.dispatchEvent(
new VectorSourceEvent(VectorEventType.FEATURESLOADSTART) new VectorSourceEvent(VectorEventType.FEATURESLOADSTART)
); );
@@ -924,6 +930,7 @@ class VectorSource extends Source {
resolution, resolution,
projection, projection,
function (features) { function (features) {
--this.loadingExtentsCount_;
this.dispatchEvent( this.dispatchEvent(
new VectorSourceEvent( new VectorSourceEvent(
VectorEventType.FEATURESLOADEND, VectorEventType.FEATURESLOADEND,
@@ -933,15 +940,17 @@ class VectorSource extends Source {
); );
}.bind(this), }.bind(this),
function () { function () {
--this.loadingExtentsCount_;
this.dispatchEvent( this.dispatchEvent(
new VectorSourceEvent(VectorEventType.FEATURESLOADERROR) new VectorSourceEvent(VectorEventType.FEATURESLOADERROR)
); );
}.bind(this) }.bind(this)
); );
loadedExtentsRtree.insert(extentToLoad, {extent: extentToLoad.slice()}); loadedExtentsRtree.insert(extentToLoad, {extent: extentToLoad.slice()});
this.loading = this.loader_ !== VOID;
} }
} }
this.loading =
this.loader_ === VOID ? false : this.loadingExtentsCount_ > 0;
} }
refresh() { refresh() {
+9
View File
@@ -28,7 +28,9 @@ import {
transform, transform,
useGeographic, useGeographic,
} from '../../../src/ol/proj.js'; } from '../../../src/ol/proj.js';
import {createXYZ} from '../../../src/ol/tilegrid.js';
import {defaults as defaultInteractions} from '../../../src/ol/interaction.js'; import {defaults as defaultInteractions} from '../../../src/ol/interaction.js';
import {tile as tileStrategy} from '../../../src/ol/loadingstrategy.js';
describe('ol.Map', function () { describe('ol.Map', function () {
describe('constructor', function () { describe('constructor', function () {
@@ -226,6 +228,13 @@ describe('ol.Map', function () {
format: new GeoJSON(), format: new GeoJSON(),
}), }),
}), }),
new VectorLayer({
source: new VectorSource({
url: 'spec/ol/data/point.json',
format: new GeoJSON(),
strategy: tileStrategy(createXYZ()),
}),
}),
new VectorLayer({ new VectorLayer({
source: new VectorSource({ source: new VectorSource({
features: [new Feature(new Point([0, 0]))], features: [new Feature(new Point([0, 0]))],