Skip to content

Commit

Permalink
begin touch zoom immediately when rotation disabled (mapbox#7582)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored and pirxpilot committed Jun 16, 2019
1 parent 7ebc02a commit 24ccce6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ui/handler/touch_zoom_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ function makeMovement(map, { rotationDisabled, aroundCenter }, e) {

if (!gestureIntent) {
const scale = vector.mag() / startVector.mag();
if (Math.abs(1 - scale) > SIGNIFICANT_SCALE_THRESHOLD) {
if (rotationDisabled && scale !== 1) {
// when rotation is disabled, any scale change triggers the zoom gesture to start
gestureIntent = 'zoom';
} else if (Math.abs(1 - scale) > SIGNIFICANT_SCALE_THRESHOLD) {
gestureIntent = 'zoom';
}
}
Expand Down
40 changes: 40 additions & 0 deletions test/unit/ui/handler/touch_zoom_rotate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,43 @@ test('TouchZoomRotateHandler does not begin a gesture if preventDefault is calle
map.remove();
t.end();
});

test('TouchZoomRotateHandler starts zoom immediately when rotation disabled', (t) => {
const map = createMap(t);
map.touchZoomRotate.disableRotation();

const zoomstart = t.spy();
const zoom = t.spy();
const zoomend = t.spy();

map.on('zoomstart', zoomstart);
map.on('zoom', zoom);
map.on('zoomend', zoomend);

simulate.touchstart(map.getCanvas(), {touches: [{clientX: 0, clientY: -5}, {clientX: 0, clientY: 5}]});
map._renderTaskQueue.run();
t.equal(zoomstart.callCount, 0);
t.equal(zoom.callCount, 0);
t.equal(zoomend.callCount, 0);

simulate.touchmove(map.getCanvas(), {touches: [{clientX: 0, clientY: -5}, {clientX: 0, clientY: 6}]});
map._renderTaskQueue.run();
t.equal(zoomstart.callCount, 1);
t.equal(zoom.callCount, 1);
t.equal(zoomend.callCount, 0);

simulate.touchmove(map.getCanvas(), {touches: [{clientX: 0, clientY: -5}, {clientX: 0, clientY: 5}]});
map._renderTaskQueue.run();
t.equal(zoomstart.callCount, 1);
t.equal(zoom.callCount, 2);
t.equal(zoomend.callCount, 0);

simulate.touchend(map.getCanvas(), {touches: []});
map._renderTaskQueue.run();
t.equal(zoomstart.callCount, 1);
t.equal(zoom.callCount, 2);
t.equal(zoomend.callCount, 1);

map.remove();
t.end();
});

0 comments on commit 24ccce6

Please sign in to comment.