How do I retrieve all properties of a feature using the map.forEachFeatureAtPixel method? When I try to use a for loop to get all properties, it doesn't work. The code provided below fetches only a single value. By employing forEachFeatureAtPixel, I am able to specify the layer from which I want to extract information. Here is the snippet:
map.on('click', function (evt) {
document.getElementById("divInformation").innerHTML = '<h1>Click for Info</h1>';
var layer;
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, featureLayer) {
layer = featureLayer;
return feature;
});
var el = document.getElementById('divInformation');
el.innerHTML = '';
if(layer === vectorLayer1){
el.innerHTML += feature.get('cod');
el.innerHTML += feature.get('date);
}else if(layer === vectorLayer2){
el.innerHTML += feature.get('name');
el.innerHTML += feature.get('Percent');
}else{
el.innerHTML = '<h1>click for Info</h1>';
}
});