2015-02-08 105 views
0
// 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传单触摸事件不是射击

传单通常应火Touchstart事件,因为它与MouseDown事件一样。但使用手机,我没有发生任何事件。

有人可以告诉我,如果在代码中有任何错误,可以防止touchevent被解雇吗?

在此先感谢。

回答

1

我加入了触摸事件的一个分支https://github.com/lee101/Leaflet/tree/add-mobile-touch-events

还有用,如果touchstart事件发生在地图上控制不被解雇touchend事件问题单张。

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

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

+0

所以,这似乎是关于MultipolygonField小部件的答案是[我的问题](http://stackoverflow.com/questions/37896208/leaflet-multipolygonfield-widget-not-receiving-touch-events),其中一个无法在手机上创建点? – raratiru 2016-06-18 11:40:24

0

因为地图本身使用触摸事件来允许缩放平移功能,所以很难获得正常的触摸事件与小册子地图正常工作。

为了避免这个问题,你可以使用这个 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"); 
}); 

问候