popup with multiple points features

£可爱£侵袭症+ 提交于 2020-01-30 12:55:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!