tdf#124179: Make it possible to drag an image using a touch gesture
First select the image (so that the circular handles show up), then
drag it.
diff --git a/loleaflet/src/dom/DomEvent.js b/loleaflet/src/dom/DomEvent.js
index 67e04c4..0d59d54 100644
--- a/loleaflet/src/dom/DomEvent.js
+++ b/loleaflet/src/dom/DomEvent.js
@@ -178,6 +178,9 @@
getMousePosition: function (e, container) {
if (!container) {
if (e.clientX === undefined && e.touches !== undefined)
return new L.Point(e.touches[0].clientX, e.touches[0].clientY);
return new L.Point(e.clientX, e.clientY);
}
@@ -192,6 +195,11 @@
left = top = 0;
}
if (e.clientX === undefined && e.touches !== undefined)
return new L.Point(
e.touches[0].clientX - left - container.clientLeft,
e.touches[0].clientY - top - container.clientTop);
return new L.Point(
e.clientX - left - container.clientLeft,
e.clientY - top - container.clientTop);
diff --git a/loleaflet/src/layer/vector/SVGGroup.js b/loleaflet/src/layer/vector/SVGGroup.js
index c719a7b..a61aa35 100644
--- a/loleaflet/src/layer/vector/SVGGroup.js
+++ b/loleaflet/src/layer/vector/SVGGroup.js
@@ -9,6 +9,11 @@
noClip: true
},
lastTouchEvent: {
clientX: 0,
clientY: 0
},
initialize: function (bounds, options) {
L.setOptions(this, options);
this._bounds = bounds;
@@ -40,6 +45,11 @@
},
_onDragStart: function(evt) {
if (evt.type === 'touchstart') {
this.lastTouchEvent.clientX = evt.touches[0].clientX;
this.lastTouchEvent.clientY = evt.touches[0].clientY;
}
if (!this._dragShape)
return;
this._moved = false;
@@ -47,6 +57,9 @@
L.DomEvent.on(this._dragShape, 'mousemove', this._onDrag, this);
L.DomEvent.on(this._dragShape, 'mouseup', this._onDragEnd, this);
L.DomEvent.on(this._dragShape, 'touchmove', this._onDrag, this);
L.DomEvent.on(this._dragShape, 'touchend', this._onDragEnd, this);
var data = {
originalEvent: evt,
containerPoint: this._map.mouseEventToContainerPoint(evt)
@@ -58,6 +71,11 @@
},
_onDrag: function(evt) {
if (evt.type === 'touchmove') {
this.lastTouchEvent.clientX = evt.touches[0].clientX;
this.lastTouchEvent.clientY = evt.touches[0].clientY;
}
if (!this._dragShape)
return;
@@ -75,11 +93,17 @@
},
_onDragEnd: function(evt) {
if (evt.type === 'touchend' && evt.touches.length == 0)
evt.touches[0] = {clientX: this.lastTouchEvent.clientX, clientY: this.lastTouchEvent.clientY};
if (!this._dragShape)
return;
L.DomEvent.off(this._dragShape, 'mousemove', this._onDrag, this);
L.DomEvent.off(this._dragShape, 'mouseup', this._onDragEnd, this);
L.DomEvent.off(this._dragShape, 'touchmove', this._onDrag, this);
L.DomEvent.off(this._dragShape, 'touchend', this._onDragEnd, this);
this._moved = false;
this._hideEmbeddedSVG();
var pos = this._map.mouseEventToLatLng(evt);
@@ -122,6 +146,7 @@
this._path.appendChild(this._rect._path);
this._dragShape = this._rect._path;
L.DomEvent.on(this._rect._path, 'mousedown', this._onDragStart, this);
L.DomEvent.on(this._rect._path, 'touchstart', this._onDragStart, this);
}
this._update();
},