Added FEATURELOADSTART, FEATURELOADEND and FEATURELOADERROR events.

This commit is contained in:
Simon Seyock
2020-10-06 12:16:15 +02:00
parent 393e83cd29
commit 1bafab49f5
5 changed files with 165 additions and 12 deletions
+32 -2
View File
@@ -40,8 +40,9 @@ export class VectorSourceEvent extends Event {
/**
* @param {string} type Type.
* @param {import("../Feature.js").default<Geometry>=} opt_feature Feature.
* @param {Array<import("../Feature.js").default<Geometry>>=} opt_features Features.
*/
constructor(type, opt_feature) {
constructor(type, opt_feature, opt_features) {
super(type);
/**
@@ -50,6 +51,13 @@ export class VectorSourceEvent extends Event {
* @api
*/
this.feature = opt_feature;
/**
* The features being loaded.
* @type {Array<import("../Feature.js").default<Geometry>>}
* @api
*/
this.features = opt_features;
}
}
@@ -904,7 +912,29 @@ class VectorSource extends Source {
}
);
if (!alreadyLoaded) {
this.loader_.call(this, extentToLoad, resolution, projection);
this.dispatchEvent(
new VectorSourceEvent(VectorEventType.FEATURESLOADSTART)
);
this.loader_.call(
this,
extentToLoad,
resolution,
projection,
function (features) {
this.dispatchEvent(
new VectorSourceEvent(
VectorEventType.FEATURESLOADEND,
undefined,
features
)
);
}.bind(this),
function () {
this.dispatchEvent(
new VectorSourceEvent(VectorEventType.FEATURESLOADERROR)
);
}.bind(this)
);
loadedExtentsRtree.insert(extentToLoad, {extent: extentToLoad.slice()});
this.loading = this.loader_ !== VOID;
}
+21
View File
@@ -34,4 +34,25 @@ export default {
* @api
*/
REMOVEFEATURE: 'removefeature',
/**
* Triggered when features starts loading.
* @event module:ol/source/Vector.VectorSourceEvent#featureloadstart
* @api
*/
FEATURESLOADSTART: 'featuresloadstart',
/**
* Triggered when features finishes loading.
* @event module:ol/source/Vector.VectorSourceEvent#featureloadend
* @api
*/
FEATURESLOADEND: 'featuresloadend',
/**
* Triggered if feature loading results in an error.
* @event module:ol/source/Vector.VectorSourceEvent#featureloaderror
* @api
*/
FEATURESLOADERROR: 'featuresloaderror',
};