Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

begin touch zoom immediately when rotation disabled #7582

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ui/handler/touch_zoom_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class TouchZoomRotateHandler {
// Determine 'intent' by whichever threshold is surpassed first,
// then keep that state for the duration of this gesture.
if (!this._gestureIntent) {
const scalingSignificantly = (Math.abs(1 - scale) > significantScaleThreshold),
// when rotation is disabled, any scale change triggers the zoom gesture to start
const scalingSignificantly = (this._rotationDisabled && scale !== 1) || (Math.abs(1 - scale) > significantScaleThreshold),
rotatingSignificantly = (Math.abs(bearing) > significantRotateThreshold);

if (rotatingSignificantly) {
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 @@ -109,3 +109,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();
});