I took the example from the docs and added another feature. On clicking the feature data will be displayed in a popup. I add another feature with different data. If I click the features in series it'll show the data from the first feature I clicked. If I click a feature, click somewhere else and then the other feature: It works like expected.
I've created a jsfiddle showing this problem. (In my firefox the map will only show if I click on the 'shield' icon in the top-left corner of the address bar and select 'Disable Protection on This Page'. See this question)
Seems like the correct feature is not taken using this example code:
// display popup on click
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, layer) {
return feature;
});
if (feature) {
var geometry = feature.getGeometry();
var coord = geometry.getCoordinates();
popup.setPosition(coord);
$(element).popover({
'placement': 'top',
'html': true,
'content': feature.get('name')
});
$(element).popover('show');
} else {
$(element).popover('destroy');
}
});
My goal is to click on the features directly one by one and get the correct data displayed.
EDIT: Seems like it's not a problem of OpenLayers but of the popover. When I insert:
console.log(feature.get('name'));
It'll come up with the correct data.