Merge pull request #11628 from simonseyock/vector-source-load-events
VectorSource load events
This commit is contained in:
@@ -40,16 +40,24 @@ 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);
|
||||
|
||||
/**
|
||||
* The feature being added or removed.
|
||||
* The added or removed feature for the `ADDFEATURE` and `REMOVEFEATURE` events, `undefined` otherwise.
|
||||
* @type {import("../Feature.js").default<Geometry>|undefined}
|
||||
* @api
|
||||
*/
|
||||
this.feature = opt_feature;
|
||||
|
||||
/**
|
||||
* The loaded features for the `FEATURESLOADED` event, `undefined` otherwise.
|
||||
* @type {Array<import("../Feature.js").default<Geometry>>|undefined}
|
||||
* @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',
|
||||
};
|
||||
|
||||
@@ -528,11 +528,22 @@ export default VectorTile;
|
||||
* @param {string} url URL.
|
||||
*/
|
||||
export function defaultLoadFunction(tile, url) {
|
||||
const loader = loadFeaturesXhr(
|
||||
url,
|
||||
tile.getFormat(),
|
||||
tile.onLoad.bind(tile),
|
||||
tile.onError.bind(tile)
|
||||
tile.setLoader(
|
||||
/**
|
||||
* @param {import("../extent.js").Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {import("../proj/Projection.js").default} projection Projection.
|
||||
*/
|
||||
function (extent, resolution, projection) {
|
||||
loadFeaturesXhr(
|
||||
url,
|
||||
tile.getFormat(),
|
||||
extent,
|
||||
resolution,
|
||||
projection,
|
||||
tile.onLoad.bind(tile),
|
||||
tile.onError.bind(tile)
|
||||
);
|
||||
}
|
||||
);
|
||||
tile.setLoader(loader);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user