ol-contextmenu icon indicating copy to clipboard operation
ol-contextmenu copied to clipboard

Context menu activating when right clicking in info popup (ol.Overlay)

Open StewartBellamy opened this issue 7 years ago • 2 comments

The context menu activates when right clicking in an ol.Overlay.

image

StewartBellamy avatar Jan 04 '18 17:01 StewartBellamy

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 avatar Sep 10 '19 14:09 nsequeira87

@nsequeira87 - Thanks, great workaround which works a treat.

StewartBellamy avatar Sep 12 '19 12:09 StewartBellamy