Skip to content

Commit

Permalink
Keep multitouch center at start center location when pinching (#6722) (
Browse files Browse the repository at this point in the history
…#7191)

* Keep multitouch center at starting center location during pinch gestures
  • Loading branch information
pakastin authored and ryanhamley committed Aug 24, 2018
1 parent 466162f commit 7e858b4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ui/handler/touch_zoom_rotate.js
Expand Up @@ -8,6 +8,7 @@ import { Event } from '../../util/evented';

import type Map from '../map';
import type Point from '@mapbox/point-geometry';
import type LngLat from '../../geo/lng_lat';
import type {TaskID} from '../../util/task_queue';

const inertiaLinearity = 0.15,
Expand All @@ -28,6 +29,7 @@ class TouchZoomRotateHandler {
_aroundCenter: boolean;
_rotationDisabled: boolean;
_startVec: Point;
_startAround: LngLat;
_startScale: number;
_startBearing: number;
_gestureIntent: 'rotate' | 'zoom' | void;
Expand Down Expand Up @@ -115,9 +117,11 @@ class TouchZoomRotateHandler {
if (e.touches.length !== 2) return;

const p0 = DOM.mousePos(this._el, e.touches[0]),
p1 = DOM.mousePos(this._el, e.touches[1]);
p1 = DOM.mousePos(this._el, e.touches[1]),
center = p0.add(p1).div(2);

this._startVec = p0.sub(p1);
this._startAround = this._map.transform.pointLocation(center);
this._gestureIntent = undefined;
this._inertia = [];

Expand Down Expand Up @@ -193,7 +197,7 @@ class TouchZoomRotateHandler {

tr.zoom = tr.scaleZoom(this._startScale * scale);

tr.setLocationAtPoint(around, aroundPoint);
tr.setLocationAtPoint(this._startAround, aroundPoint);

this._map.fire(new Event(gestureIntent, {originalEvent: this._lastTouchEvent}));
this._map.fire(new Event('move', {originalEvent: this._lastTouchEvent}));
Expand Down

0 comments on commit 7e858b4

Please sign in to comment.