Skip to content

Commit

Permalink
Merge pull request #1504 from origo-map/featinfo-geojson
Browse files Browse the repository at this point in the history
Fetch feature info in application/geo+json format
  • Loading branch information
johnnyblasta authored Mar 24, 2022
2 parents 9b6f006 + 817172f commit ffb99dd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/getfeatureinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ function getFeatureInfoUrl({
resolution,
projection
}, layer) {
if (layer.get('infoFormat') === 'application/geo+json' || layer.get('infoFormat') === 'application/geojson') {
const url = layer.getSource().getFeatureInfoUrl(coordinate, resolution, projection, {
INFO_FORMAT: layer.get('infoFormat'),
FEATURE_COUNT: '20'
});

return fetch(url, { type: 'GET' })
.then((res) => {
if (res.error) {
return [];
}
return res.json();
})
.then(json => {
if (json.features.length > 0) {
const copyJson = json;
copyJson.features.forEach((item, i) => {
if (!item.geometry) {
copyJson.features[i].geometry = { type: 'Point', coordinates: coordinate };
}
});
const feature = maputils.geojsonToFeature(copyJson);
return feature;
}
return [];
})
.catch(error => console.error(error));
}
const url = layer.getSource().getFeatureInfoUrl(coordinate, resolution, projection, {
INFO_FORMAT: 'application/json',
FEATURE_COUNT: '20'
Expand Down

0 comments on commit ffb99dd

Please sign in to comment.