2015-02-08 60 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"); 
}); 

問候