【问题标题】:Update or destroy popup in openlayers3在 openlayers3 中更新或销毁弹出窗口
【发布时间】:2015-05-13 12:32:45
【问题描述】:

我尝试使用带有一组标记和弹出窗口的 openlayers3 构建地图。到目前为止,标记和弹出窗口都有效,但是当我单击一个标记(显示弹出窗口)然后 - 无需再次单击地图 - 另一个标记时,它会显示一个与第一个内容相同的弹出窗口。我已经做过研究,但找不到有用的东西。所以这是我的弹出窗口的部分:

//popup
var element = document.getElementById('popup');

var popup = new ol.Overlay({
  element: element,
  positioning: 'bottom-center',
  stopEvent: false
});

map.addOverlay(popup);

// display popup on click
map.on('click', function(evt) { 
  var feature = map.forEachFeatureAtPixel(evt.pixel,
      function(feature, layer) {
        return feature;
      });     

  if (feature) {
    var geometry = feature.getGeometry();
    var coord = geometry.getCoordinates();
    popup.setPosition(coord);
    $(element).popover({
      'placement': 'top',
      'html': true,
      'content': feature.get('information')
    });
    $(element).popover('show');
  } else {
    $(element).popover('destroy');
  }
});

希望有人可以帮助我。谢谢!

【问题讨论】:

  • 对于 OL3,它有助于指定确切的版本。弹出窗口处理在点发布中经常发生变化。

标签: popup openlayers-3


【解决方案1】:

我遇到了同样的问题,在这里找到了我的解决方案 https://gis.stackexchange.com/questions/137561/openlayers-3-markers-and-popovers

尝试改变你的

$(element).popover({
  'placement': 'top',
  'html': true,
  'content': feature.get('information')
});

$(element).attr('data-placement', 'top');
$(element).attr('data-html', true);
$(element).attr('data-content', feature.get('information'));

【讨论】:

    【解决方案2】:

    我为你做了一个例子。看看吧!

    你必须在每个标记上“写”一些内容。

    http://embed.plnkr.co/hhEAWk/preview

    【讨论】:

      猜你喜欢
      • 2018-12-03
      • 1970-01-01
      • 2012-03-04
      • 2017-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 2011-01-18
      相关资源
      最近更新 更多