[GIS] How to select a feature in Openlayers 3 by right click it

javascriptopenlayers

I'm trying to selete / delete a feature by right click it on Openlayers 3.
I know I have map events singleclick/click/dblclick and I also know I can use the ol.interaction.Select for delete.

In openlayers 2 I recall I could use oncontextmenu.

How can I achieve such a thing using OL3 ?

Best Answer

UPDATE:


I've ended up developing a custom contextmenu extension for OpenLayers. It has a lot of features like callbacks. Here's a preview:

enter image description here

You can use:

map.getViewport().addEventListener('contextmenu', function (e) {
    e.preventDefault();

    console.info('contextmenu');
    var feature = map.forEachFeatureAtPixel(map.getEventPixel(e),
        function (feature, layer) {
            return feature;
        });
    if (feature) {

        // ...
    }
});

Tested: Firefox && Chrome

Reference: https://groups.google.com/d/msg/ol3-dev/yCgIcbURw9M/jeWH1aZcK_0J