I'm working with openLayers 3, which is new to me, and I've been able to add a popup to my map that comes up when you click on a feature in a vector layer. The trouble is the popup content does not update when you click on another feature; you need to click on an area where there isn't a feature to close it, then click on another feature for the popup content to refresh. I'd like for the popup content to update when you click on a new feature, without having to click on an area where there is not feature first. Is there a way I can do this? Here is the code for the popup that I am using:
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, layer) {
return feature;
});
if (feature) {
popup.setPosition(evt.coordinate);
$(element).popover({
'placement': 'top',
'html': true,
'content': '<b>Parcel No: </b><br>'+
feature.get('parcel')+'<br>'+
'<b>Owner: </b><br>'+
feature.get('primowner')
});
$(element).popover('show');
} else {
$(element).popover('destroy');
}
});