我正在尝试创建一个点击+按住事件来创建新的标记位置(点击+按住事件仅适用于移动应用程序);这些事件处理程序未按预期工作(发生了一些覆盖)
我尝试使用map.on('touchstart'...)、map.on('mousedown'...)和其他变体,但事件代码仅在touchend或mouseup完成后触发。
me.mapLibObj.on( 'touchstart', function(e)
{
if ( ! me.mapTapHoldInterval )
{
me.mapTapHoldInterval = setInterval( function() {
me.mapDownIntvCounter += 1
if ( me.mapDownIntvCounter > 20 )
{
me.defaultCoordinatePoint = [ e.latlng.lat,e.latlng.lng ];
me.createMyCoordinateMarker( true );
clearInterval( me.mapTapHoldInterval );
}
}, 100 )
}
} );
me.mapLibObj.on( 'touchend', function(e)
{
if ( me.mapTapHoldInterval )
{
clearInterval( me.mapTapHoldInterval );
}
} );
最佳答案
我建议您查看 contextmenu 事件: https://leafletjs.com/reference-1.7.1.html#map-interaction-events
map.on('contextmenu', (e) => {
console.log('Lat, Lon:', e.latlng.lat + ',' + e.latlng.lng);
});
关于leaflet - 如何在Leaflet map 上实现点击+按住(长按)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56427289/