I'm using GeoServer and I need to put the value of NDVI from four different wms into a chart. I'm using also OpenLayer for my map.
map.on('singleclick', function(evt) {
var viewResolution = view.getResolution();
var ndvi_array = [], ndvi_20200706, ...
var url_20200706 = sourceNDVI_20200706.getFeatureInfoUrl(
evt.coordinate, viewResolution, 'EPSG:3857',
{
'INFO_FORMAT': 'application/json',
'propertyName': 'GRAY_INDEX',
});
console.log(url_20200706);
fetch(url_20200706)
.then(function (response) {
return response.text(); })
.then(function (data) {
var json = JSON.parse(data).features[0];
var ndvi_20200706 = json.properties.GRAY_INDEX;
}).catch((error) => {
console.warn(error)
});
console.log("NDVI 6 luglio 2020: "+ndvi_20200706);
ndvi_array.push(ndvi_20200706);
var url_20190706 = sourceNDVI_20190706.getFeatureInfoUrl(
evt.coordinate, viewResolution, 'EPSG:3857',
{
'INFO_FORMAT': 'application/json',
'propertyName': 'GRAY_INDEX',
});
console.log(url_20190706);
fetch(url_20190706)
.then(function (response) {
return response.text(); })
.then(function (data) {
var json = JSON.parse(data).features[0];
var ndvi_20190706 = json.properties.GRAY_INDEX;
}).catch((error) => {
console.warn(error)
});
.
.
.
console.log("Array: "+ndvi_array);
});
I'm be able to see on the map all wms.
EDIT 1
Probably my question isn't clear and I've edit the code with all my purpouse. What I want to do is put the NDVI index of all WMS into an array because I need to use an array for a chart.
EDIT 2(after @Mike indications)
I've edited all code, now in console log I see this when I click on a point:
NDVI 6 luglio 2020: undefined Array:
Uncaught TypeError: url_20200706.features is undefined
. Where I must set the CORS support?url_20200706
is a url string, it does not have a features property, the url needs to be fetched.getFeatureInfoUrl
you must fetch the url to obtain the data