OpenLayers 3 – Obtaining Pixel from Right-Click Event

openlayers

In the 'click' event with the left mouse button I have the variable 'pixel' (an array with x and y), which can be used by 'forEachFeatureAtPixel':

map.forEachFeatureAtPixel(event.pixel, function (feature, layer) {})

In contrast, in the event "contextmenu" is not there at all and I cannot use the function "forEachFeatureAtPixel". How can I do this?

Best Answer

Found the solution! We can you can use getEventPixel function to obtain Pixel.

map.getEventPixel(event)

So this is the code that gets all the features on that spot:

map.forEachFeatureAtPixel(map.getEventPixel(event), function (feature, layer) {})