0

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

giacomo
  • 51
  • 1
  • 10
  • Are you trying to do something like [this](http://www.geocodezip.com/OL_5.3.0_simpleMultipleMarkerExample.html)? – geocodezip Dec 27 '18 at 19:21
  • Or possibly like [this](http://www.geocodezip.com/OL_zoomToMarkers.html)? – geocodezip Dec 28 '18 at 01:50
  • @geocodezip There's a problem is with bootstrap popups which can be reproduced by adding a second icon to the OpenLayers example http://mikenunn.16mb.com/demo/icons-error.html http://mikenunn.16mb.com/demo/icons-fixed.html – Mike Dec 28 '18 at 10:26
  • i've looked here and solved (adding popup-content) https://openlayers.org/en/latest/examples/popup.html – giacomo Dec 29 '18 at 17:43

1 Answers1

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

Mike
  • 16,042
  • 2
  • 14
  • 30
  • thanks, i tried without timeout, and it did not worked (i've not tried with timeout, solved anyway with popup content) – giacomo Dec 28 '18 at 10:59
  • Yes, if it can be done without bootstrap and bootstrap doesn't work properly then best not use it! – Mike Dec 28 '18 at 11:16