Clarification and use callbacks in examples
This commit is contained in:
@@ -56,7 +56,7 @@ const styleCache = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const vectorSource = new VectorSource({
|
const vectorSource = new VectorSource({
|
||||||
loader: function (extent, resolution, projection) {
|
loader: function (extent, resolution, projection, success, failure) {
|
||||||
const url =
|
const url =
|
||||||
serviceUrl +
|
serviceUrl +
|
||||||
layer +
|
layer +
|
||||||
@@ -83,6 +83,7 @@ const vectorSource = new VectorSource({
|
|||||||
alert(
|
alert(
|
||||||
response.error.message + '\n' + response.error.details.join('\n')
|
response.error.message + '\n' + response.error.details.join('\n')
|
||||||
);
|
);
|
||||||
|
failure();
|
||||||
} else {
|
} else {
|
||||||
// dataProjection will be read from document
|
// dataProjection will be read from document
|
||||||
const features = esrijsonFormat.readFeatures(response, {
|
const features = esrijsonFormat.readFeatures(response, {
|
||||||
@@ -91,8 +92,10 @@ const vectorSource = new VectorSource({
|
|||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
vectorSource.addFeatures(features);
|
vectorSource.addFeatures(features);
|
||||||
}
|
}
|
||||||
|
success(features);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
error: failure,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
strategy: tileStrategy(
|
strategy: tileStrategy(
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ const styles = {
|
|||||||
|
|
||||||
const vectorSource = new VectorSource({
|
const vectorSource = new VectorSource({
|
||||||
format: new OSMXML(),
|
format: new OSMXML(),
|
||||||
loader: function (extent, resolution, projection) {
|
loader: function (extent, resolution, projection, success, failure) {
|
||||||
const epsg4326Extent = transformExtent(extent, projection, 'EPSG:4326');
|
const epsg4326Extent = transformExtent(extent, projection, 'EPSG:4326');
|
||||||
const client = new XMLHttpRequest();
|
const client = new XMLHttpRequest();
|
||||||
client.open('POST', 'https://overpass-api.de/api/interpreter');
|
client.open('POST', 'https://overpass-api.de/api/interpreter');
|
||||||
@@ -83,7 +83,9 @@ const vectorSource = new VectorSource({
|
|||||||
featureProjection: map.getView().getProjection(),
|
featureProjection: map.getView().getProjection(),
|
||||||
});
|
});
|
||||||
vectorSource.addFeatures(features);
|
vectorSource.addFeatures(features);
|
||||||
|
success(features);
|
||||||
});
|
});
|
||||||
|
client.addEventListener('error', failure);
|
||||||
const query =
|
const query =
|
||||||
'(node(' +
|
'(node(' +
|
||||||
epsg4326Extent[1] +
|
epsg4326Extent[1] +
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ let withCredentials = false;
|
|||||||
* the area to be loaded, a `{number}` representing the resolution (map units per pixel), an
|
* the area to be loaded, a `{number}` representing the resolution (map units per pixel), an
|
||||||
* {@link module:ol/proj/Projection} for the projection, an optional success callback that should get
|
* {@link module:ol/proj/Projection} for the projection, an optional success callback that should get
|
||||||
* the loaded features passed as an argument and an optional failure callback with no arguments. If
|
* the loaded features passed as an argument and an optional failure callback with no arguments. If
|
||||||
* the callbacks are not used, the corresponding vector source will not fire `'featuresloadstart'`,
|
* the callbacks are not used, the corresponding vector source will not fire `'featuresloadend'` and
|
||||||
* `'featuresloadend'` and `'featuresloaderror'` events. `this` within the function is bound to the
|
* `'featuresloaderror'` events. `this` within the function is bound to the
|
||||||
* {@link module:ol/source/Vector} it's called from.
|
* {@link module:ol/source/Vector} it's called from.
|
||||||
*
|
*
|
||||||
* The function is responsible for loading the features and adding them to the
|
* The function is responsible for loading the features and adding them to the
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class VectorSourceEvent extends Event {
|
|||||||
* @property {import("../featureloader.js").FeatureLoader} [loader]
|
* @property {import("../featureloader.js").FeatureLoader} [loader]
|
||||||
* The loader function used to load features, from a remote source for example.
|
* The loader function used to load features, from a remote source for example.
|
||||||
* If this is not set and `url` is set, the source will create and use an XHR
|
* If this is not set and `url` is set, the source will create and use an XHR
|
||||||
* feature loader. The `'featuresloadstart'`, `'featuresloadend'` and `'featuresloaderror'` events
|
* feature loader. The `'featuresloadend'` and `'featuresloaderror'` events
|
||||||
* will only fire if the `success` and `failure` callbacks are used.
|
* will only fire if the `success` and `failure` callbacks are used.
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
|
|||||||
Reference in New Issue
Block a user