Skip to content

Commit

Permalink
fix: make getfeatureinfo requests not fail together (#2003)
Browse files Browse the repository at this point in the history
* fix: make getfeatureinfo requests not fail together

* fix: add console message about what layer did not perform as expected
  • Loading branch information
Grammostola authored May 20, 2024
1 parent 67d8595 commit d4626e3
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/getfeatureinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,23 +319,27 @@ function getFeatureInfoRequests({
return requests;
}

function getFeaturesFromRemote(requestOptions, viewer, textHtmlHandler) {
async function getFeaturesFromRemote(requestOptions, viewer, textHtmlHandler) {
const requestResult = [];
const requestPromises = getFeatureInfoRequests(requestOptions, viewer, textHtmlHandler).map((request) => request.fn.then((features) => {
const layer = viewer.getLayer(request.layer);
const groupLayers = viewer.getGroupLayers();
const map = viewer.getMap();
if (features) {
features.forEach((feature) => {
const requests = getFeatureInfoRequests(requestOptions, viewer, textHtmlHandler);
const featureInfoPromises = requests.map((request) => request.fn);
const featureInfoPromisesResults = await Promise.allSettled(featureInfoPromises);

featureInfoPromisesResults.forEach((result, i) => {
const layer = viewer.getLayer(requests[i].layer);
if (result.status === 'fulfilled' && result.value) {
const groupLayers = viewer.getGroupLayers();
const map = viewer.getMap();
result.value.forEach((feature) => {
const si = createSelectedItem(feature, layer, map, groupLayers);
requestResult.push(si);
});
return requestResult;
} else {
console.warn(`GetFeatureInfo request failed for layer: ${layer.get('name')}`);
}
});

return false;
}));
return Promise.all([...requestPromises]).then(() => requestResult).catch(error => console.log(error));
return requestResult;
}

function getFeaturesAtPixel({
Expand Down

0 comments on commit d4626e3

Please sign in to comment.