mirror of
https://github.com/visgl/react-map-gl.git
synced 2026-01-18 15:54:22 +00:00
use 'changedTouches' for 'touchend'/'touchcancel' events (#164)
closes #139
This commit is contained in:
parent
190dc3d575
commit
1625df150d
@ -45,15 +45,26 @@ function getMousePosition(el, event) {
|
||||
function getTouchPositions(el, event) {
|
||||
const points = [];
|
||||
const rect = el.getBoundingClientRect();
|
||||
for (let i = 0; i < event.touches.length; i++) {
|
||||
const touches = getTouches(event);
|
||||
for (let i = 0; i < touches.length; i++) {
|
||||
points.push([
|
||||
event.touches[i].clientX - rect.left - el.clientLeft,
|
||||
event.touches[i].clientY - rect.top - el.clientTop
|
||||
touches[i].clientX - rect.left - el.clientLeft,
|
||||
touches[i].clientY - rect.top - el.clientTop
|
||||
]);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
// Get relevant touches from event depending on event type (for `touchend` and
|
||||
// `touchcancel` the property `changedTouches` contains the relevant coordinates)
|
||||
function getTouches(event) {
|
||||
const type = event.type;
|
||||
if (type === 'touchend' || type === 'touchcancel') {
|
||||
return event.changedTouches;
|
||||
}
|
||||
return event.touches;
|
||||
}
|
||||
|
||||
// Return the centroid of an array of points
|
||||
function centroid(positions) {
|
||||
const sum = positions.reduce(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user