Merge pull request #11882 from simonseyock/vector-source-load-events-doc

Improved documentation for feature load events.
This commit is contained in:
Andreas Hocevar
2021-01-07 22:36:20 +01:00
committed by GitHub
4 changed files with 20 additions and 10 deletions

View File

@@ -56,7 +56,7 @@ const styleCache = {
};
const vectorSource = new VectorSource({
loader: function (extent, resolution, projection) {
loader: function (extent, resolution, projection, success, failure) {
const url =
serviceUrl +
layer +
@@ -83,6 +83,7 @@ const vectorSource = new VectorSource({
alert(
response.error.message + '\n' + response.error.details.join('\n')
);
failure();
} else {
// dataProjection will be read from document
const features = esrijsonFormat.readFeatures(response, {
@@ -91,8 +92,10 @@ const vectorSource = new VectorSource({
if (features.length > 0) {
vectorSource.addFeatures(features);
}
success(features);
}
},
error: failure,
});
},
strategy: tileStrategy(

View File

@@ -74,7 +74,7 @@ const styles = {
const vectorSource = new VectorSource({
format: new OSMXML(),
loader: function (extent, resolution, projection) {
loader: function (extent, resolution, projection, success, failure) {
const epsg4326Extent = transformExtent(extent, projection, 'EPSG:4326');
const client = new XMLHttpRequest();
client.open('POST', 'https://overpass-api.de/api/interpreter');
@@ -83,7 +83,9 @@ const vectorSource = new VectorSource({
featureProjection: map.getView().getProjection(),
});
vectorSource.addFeatures(features);
success(features);
});
client.addEventListener('error', failure);
const query =
'(node(' +
epsg4326Extent[1] +