From cd1a2472d557d91f9ac6cb987da53e3e84eea24b Mon Sep 17 00:00:00 2001 From: David Date: Thu, 2 May 2024 14:09:19 +0200 Subject: [PATCH] fix: make getfeatureinfo requests not fail together --- src/getfeatureinfo.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/getfeatureinfo.js b/src/getfeatureinfo.js index 503d533e1..7e6abbeab 100644 --- a/src/getfeatureinfo.js +++ b/src/getfeatureinfo.js @@ -319,23 +319,25 @@ 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) => { + if (result.status === 'fulfilled' && result.value) { + const layer = viewer.getLayer(requests[i].layer); + const groupLayers = viewer.getGroupLayers(); + const map = viewer.getMap(); + result.value.forEach((feature) => { const si = createSelectedItem(feature, layer, map, groupLayers); requestResult.push(si); }); - return requestResult; } + }); - return false; - })); - return Promise.all([...requestPromises]).then(() => requestResult).catch(error => console.log(error)); + return requestResult; } function getFeaturesAtPixel({