giacomo
giacomo

Reputation: 61

popup with multiple points features

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

Upvotes: 0

Views: 1644

Answers (1)

Mike
Mike

Reputation: 17962

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

Upvotes: 1

Related Questions