map.on('contextmenu', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, layer) {
return feature;
});
if (feature) {
evt.preventDefault();
// ...
}
});
--
You received this message because you are subscribed to the Google Groups "OL3 Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ol3-dev+u...@googlegroups.com.
To post to this group, send email to ol3...@googlegroups.com.
Visit this group at http://groups.google.com/group/ol3-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/ol3-dev/089dae24-5ae3-4a35-893b-7f5fb60ba5cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Le 4 nov. 2014 17:20, "Onox via OL3 Dev" <ol3-dev+noreply-APn2wQdKbSciCKHv...@googlegroups.com> a écrit :
>
> Thanks for your answer, but I can't get it to work. I tried testing for the originalEvent.button subproperty of the 'click' and 'singleclick' events, but actually when I right-click no event is fired at all. How do you do it please ?
You use the browser event API or a lib like jQuery to register a "contextmenu" listener on the map viewport. E.g. with jQuery:
$(map.getViewport()).on('contextmenu', function(e) {
var coord = map.getEventCoordinate(e);
...
});
Untested.
map.getViewport().addEventListener('contextmenu', function (e) { // or $(map.getViewport()).on('contextmenu', function(e) with jQuery
e.preventDefault();
var feature = map.forEachFeatureAtPixel(map.getEventPixel(e),
function (feature, layer) {
return feature;
});
if (feature) {
// ...
}
});
--
You received this message because you are subscribed to a topic in the Google Groups "OL3 Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ol3-dev/yCgIcbURw9M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ol3-dev+unsubscribe@googlegroups.com.
To post to this group, send email to ol3...@googlegroups.com.
Visit this group at https://groups.google.com/group/ol3-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/ol3-dev/1cfe4c46-adfb-44e5-8fcb-38ed4e4e8e48%40googlegroups.com.