How to prevent feature clicks through popup?

2019-08-15 05:54发布

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条回答
男人必须洒脱
2楼-- · 2019-08-15 06:13

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.

查看更多
登录 后发表回答