Added FEATURELOADSTART, FEATURELOADEND and FEATURELOADERROR events.
This commit is contained in:
@@ -27,7 +27,7 @@ let withCredentials = false;
|
||||
* import("./extent.js").Extent,
|
||||
* number,
|
||||
* import("./proj/Projection.js").default,
|
||||
* function(): void=,
|
||||
* function(Array<import("./Feature.js").default>): void=,
|
||||
* function(): void=): void} FeatureLoader
|
||||
* @api
|
||||
*/
|
||||
@@ -134,14 +134,14 @@ export function xhr(url, format) {
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||
* @param {function(): void} success Success
|
||||
* @param {function(): void=} success Success
|
||||
* Function called when loading succeeded.
|
||||
* @param {function(): void} failure Failure
|
||||
* @param {function(): void=} failure Failure
|
||||
* Function called when loading failed.
|
||||
* @this {import("./source/Vector").default}
|
||||
*/
|
||||
return function (extent, resolution, projection, success, failure) {
|
||||
const sourceOrTile = /** @type {import("./source/Vector").default} */ (this);
|
||||
const source = /** @type {import("./source/Vector").default} */ (this);
|
||||
loadFeaturesXhr(
|
||||
url,
|
||||
format,
|
||||
@@ -154,9 +154,12 @@ export function xhr(url, format) {
|
||||
* projection.
|
||||
*/
|
||||
function (features, dataProjection) {
|
||||
sourceOrTile.addFeatures(features);
|
||||
if (success !== undefined) {
|
||||
success(features);
|
||||
}
|
||||
source.addFeatures(features);
|
||||
},
|
||||
/* FIXME handle error */ VOID
|
||||
/* FIXME handle error */ failure ? failure : VOID
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user