问题
i'm having some troubles with open layer 5 looking/coping this example https://openlayers.org/en/latest/examples/icon.html?q=marker
having more than one "clickable icon" if i click and open the popup is ok, then if i click the map (not icons) the popup goes away, well! but if i've a popover opened on the first icon, and then i click another one icon, the ballon move up the next, but the content is not changed...
where i'm wrong!? thanks
回答1:
You need to destroy the old popup before creating a new one. But there may be a problem with destroy followed immediately by recreate, see Bootstrap popover destroy & recreate works only every second time so you may need a short timeout and the update to the relevant code in the example would look like
if (feature) {
$(element).popover('destroy');
setTimeout(function () {
var coordinates = feature.getGeometry().getCoordinates();
popup.setPosition(coordinates);
$(element).popover({
'placement': 'top',
'html': true,
'content': feature.get('name')
});
$(element).popover('show');
}, 200);
} else {
$(element).popover('destroy');
}
or you could try a solution based one of the other answers in that question
来源:https://stackoverflow.com/questions/53947527/popup-with-multiple-points-features