Merge pull request #11941 from ahocevar/strategy-loading
Fix loading flag for vector loading strategies
This commit is contained in:
@@ -234,6 +234,12 @@ class VectorSource extends Source {
|
||||
*/
|
||||
this.loadedExtentsRtree_ = new RBush();
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.loadingExtentsCount_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object<string, import("../Feature.js").default<Geometry>>}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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]))],
|
||||
|
||||
Reference in New Issue
Block a user