如何在OpenLayers5上获取长按,右键单击或此类事件?

问题描述 投票:-1回答:1

我想得到一些指针事件

  • 长龙头
  • 右键点击

是否有任何存档示例或文档?

注意:我将相同的问题提交给“地理信息系统”,但我再次将其添加到Stack Overflow,因为Openlayers官方的github建议将问题发布到Stack Overflow。

gis openlayers openlayers-3
1个回答
0
投票

我自己找到了解决方案,以便长时间使用:

    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;
    });
© www.soinside.com 2019 - 2024. All rights reserved.