OpenLayers Events – How to Get Long Tap, Right Click, or Other Events on OpenLayers5

javascriptopenlayers

I want to get some pointer events like

  • long tap
  • right click

Are there any examples or documentations for archive them?

Best Answer

I found the solution by myself for long tap:

var longpress = false;
map.on("click",function(e){
    (longpress) ? alert("Long Press") : alert("Short Press");
    console.log(map.getEventCoordinate(e.pixel));
});
var startTime, endTime;
map.on('pointerdown', function () {
    startTime = new Date().getTime();
});
map.on('pointerup', function () {
    endTime = new Date().getTime();
    console.log(endTime - startTime);
    longpress = (endTime - startTime < 500) ? false : true;
});