From 834583bc8ad1324d437dde5dec2d2cf8ba3908f9 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 14 Dec 2024 09:15:04 +0100 Subject: [PATCH] Update getfeatureinfo.js --- src/getfeatureinfo.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/getfeatureinfo.js b/src/getfeatureinfo.js index 8bebaa568..ca6959c2f 100644 --- a/src/getfeatureinfo.js +++ b/src/getfeatureinfo.js @@ -146,15 +146,18 @@ async function getFeatureInfoUrl({ const format = layer.get('infoFormat'); const formatArr = [...new Set([format, 'application/geo+json', 'application/geojson', 'application/json'])]; let text; - for (const f of formatArr) { + for (let i = 0; i < formatArr.length; i += 1) { + const format = formatArr[i]; const url = layer.getSource().getFeatureInfoUrl(coordinate, resolution, projection, { - INFO_FORMAT: f, + INFO_FORMAT: format, FEATURE_COUNT: '20' }); - const res = await fetch(url, { method: 'GET' }); - text = await res.text(); - if (isValidJSON(text)) { - layer.set('infoFormat', f); + // eslint-disable-next-line no-await-in-loop + const result = await fetch(url, { method: 'GET' }).then((res) => res.text()) + .catch(error => console.error(error)); + if (isValidJSON(result)) { + text = result; + layer.set('infoFormat', format); break; } }