openlayer 3 长按事件

openlayer 3没有长按事件,通过常用事件模拟长按事件。

 /***
	 *地图 长按事件
	 */
	var longpress = false;
	//click 事件 
	map.on("click",function(){
	   (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;
    });


转载自:https://blog.csdn.net/wanwanwan123/article/details/51111448

You may also like...