传单触摸事件未触发

Leaflet Touch Events not firing

本文关键字:事件 触摸 单触摸      更新时间:2023-09-26
    // Setup map
var polymap = L.map('map').setView([51.932994, 4.509373], 14);
// Setup tilelayer
var mapquestUrl = 'http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png',
    subDomains = ['otile1', 'otile2', 'otile3', 'otile4'],
    mapquestAttrib = 'Data, imagery and map information provided by <a href="http://open.mapquest.co.uk" target="_blank">MapQuest</a>,' 
    + '<a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMap</a> and contributors.';
var osm = L.tileLayer(mapquestUrl, {
    attribution: mapquestAttrib,
    subdomains: subDomains
});
polymap.addLayer(osm);
polymap.on('mousedown touchstart', function onMouseDown(event) {
    alert("start");
});

JSFiddle

传单通常应该像mousedown事件一样触发touchstart事件,但使用手机,我没有触发任何事件。

有人可以告诉我代码中是否有任何错误,从而阻止touchevent触发吗?

我已将触摸事件添加到分支中的传单 https://github.com/lee101/Leaflet/tree/add-mobile-touch-events

如果地图控件上发生触摸启动事件,则触摸端事件未触发仍然存在问题。

克隆

存储库后,您可以使用npm install && jake构建源代码。

我希望在解决问题后将其贡献回来。

使用

传单地图很难使正常的触摸事件正常工作,因为地图本身使用触摸事件来允许缩放和平移功能。

为避免此问题,您可以使用此用于捕获特定触摸事件的库(点击,双击,按下,轻拂,拖动(

<script src="http://domain.ltd/path/jquery.finger.js"></script>

$.Finger = {
    pressDuration: 300,
    doubleTapInterval: 300,
    flickDuration: 150,
    motionThreshold: 5
};
polymap.on('tap', function(e) {
    alert("start");
});

此致敬意