How to prevent feature clicks through popup?

我的未来我决定 提交于 2019-12-11 13:34:57

问题


I need a popup to be opened when clicking on the features of a vector layer. I used the Vector Icon Example as starting point. My problem is that when a feature is covered by the popup, you can still click it (Fiddle-Demo: click the lower point and you can click the upper one through the popup). How can prevent this behavior?

Relevant code:

map.on('click', function(evt) {
    var element = popup.getElement();
    $(element).popover({
    "placement": "top",
    "html": true
}); 
var popover = $(element).data("bs.popover");
var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
    return feature;
});
if (feature) {
    popup.setPosition(feature.getGeometry().getCoordinates());
    popover.options.content = feature.get("name");
    $(element).popover('show');
} else {
    $(element).popover('destroy');
}
});

回答1:


Set stopEvent: true to your ol.Overlay object, as such:

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

See your updated Fiddle demo.



来源:https://stackoverflow.com/questions/33936795/how-to-prevent-feature-clicks-through-popup

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