Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse rightclick on Openlayer 3

Is is possible to get the mouse right click event on Openlayer3? If so how can i get the latitude and longitude of the right clicked location.

i have got the right click event by following

map.getViewport().addEventListener('contextmenu', function (evt) {

});

How can i get the latitude and longitude of the right clicked point?

like image 420
Kiran k g Avatar asked Jan 05 '17 05:01

Kiran k g


1 Answers

Use the map.getEventCoordinate method to get your coords. Also use the evt.preventDefault() to get rid of the native right click menu.

map.getViewport().addEventListener('contextmenu', function (evt) {
evt.preventDefault();
console.log(map.getEventCoordinate(evt));

})
like image 86
pavlos Avatar answered Nov 02 '22 13:11

pavlos