7

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 ?

nagytech
  • 3,741
  • 18
  • 37
Alophind
  • 2,707
  • 5
  • 40
  • 75

1 Answers1

11

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

Jonatas Walker
  • 2,214
  • 13
  • 26