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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.