ol-contextmenu
ol-contextmenu copied to clipboard
Context menu activating when right clicking in info popup (ol.Overlay)
The context menu activates when right clicking in an ol.Overlay.
For future readers, my workaround on this one was giving an Id to the popup element and then:
contextMenu.on('beforeopen', (evt) => {
var element = map.getTargetElement();
var { top, left } = element.getBoundingClientRect();
if (document.elementsFromPoint(evt.pixel[0] + left, evt.pixel[1] + top).some(e => e.id === 'ID_OF_POPUP_ELEMENT')) {
contextMenu.disable();
return;
}
//remaining logic...
}
I had to get TOP/LEFT map position, because evt.pixel's position is relative to the map. You might want to add scroll's position too, I didn't need it in my case. Then I check all elements on the cursor position and check if my popup is there or not.
@nsequeira87 - Thanks, great workaround which works a treat.