The fix for 'touchend' not firing on mobile devices
Opened this issue · 1 comments
I think this is not an issue with the plugin, but with Leaflet itself and this might be useful to know there is a bug in Leaflet which prevents 'touchend' events from firing when running on mobile devices with touch.
Generally speaking this bug prevents Leaflet.draw from firing '_fireEdit' functions which are responsible for setting layer as edited this will never fire on 'touchend':
_fireEdit: function () {
this._shape.edited = true;
this._shape.fire('edit');
}
I managed to fix the issue by modifying Leaflet (version 0.7.7) source code to fire 'touchend', line 7069.
The original Leaflet function:
function onTouchEnd(e) {
if (L.Browser.pointer) {
var idx = trackedTouches.indexOf(e.pointerId);
if (idx === -1) {
return;
}
trackedTouches.splice(idx, 1);
}
...
}
And here is the fix:
function onTouchEnd(e) {
if (L.Browser.pointer) {
var idx = trackedTouches.indexOf(e.pointerId);
if (idx === -1) {
return;
}
trackedTouches.splice(idx, 1);
}
else if (touch) {
touch.type = 'touchend';
handler(touch);
}
...
}
Edited by @ddproxy to fix code blocks
Leaflet/Leaflet#4168
Leaflet/Leaflet#1542
Not sure if we can sneak this fix into 0.7.7 - and with 1.0.0-beta.2 released four months ago I'm not sure where they are at in release 1.x.