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 ?

1 Answer 1



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) {

    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

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .