如何防止功能部件通过弹出窗口单击?
问题描述:
单击矢量层的要素时,需要打开一个弹出窗口.我以矢量图标示例为起点.我的问题是,当弹出菜单包含某个功能时,您仍然可以单击它( Fiddle-Demo :单击较低的位置,则可以通过弹出窗口单击上方的位置).如何防止这种行为?
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?
相关代码:
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');
}
});
答
将stopEvent: true
设置为ol.Overlay
对象,例如:
var popup = new ol.Overlay({
element: element,
positioning: 'bottom-center',
stopEvent: true
});
请参阅您的更新的Fiddle演示.