单张触摸事件未触发

时间:2015-02-08 15:08:27

标签: javascript javascript-events touch leaflet openstreetmap

    // 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

Leaflet通常应该像使用Mousedown事件一样触发Touchstart事件。但是使用手机,我没有被解雇。

有人可以告诉我代码中是否有任何错误,这会阻止触发器被触发?

提前致谢。

2 个答案:

答案 0 :(得分:1)

我已在分支https://github.com/lee101/Leaflet/tree/add-mobile-touch-events

中向传单添加了触摸事件

如果在地图控件上发生touchstart事件,那么touchend事件仍然会出现问题。

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

在我解决这个问题后,我希望能够回馈它。

答案 1 :(得分:0)

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

要避免此问题,您可以使用此功能 library捕捉特定触摸事件(点按,双击,按,轻弹,拖动)

<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");
});

祝你好运

相关问题