From cf88c31c704788ffad24f8e92103087677355d3c Mon Sep 17 00:00:00 2001 From: Michael Barry Date: Mon, 12 Nov 2018 13:57:50 -0500 Subject: [PATCH] begin touch zoom immediately when rotation disabled (#7582) --- src/ui/handler/touch_zoom_rotate.js | 5 ++- .../unit/ui/handler/touch_zoom_rotate.test.js | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/ui/handler/touch_zoom_rotate.js b/src/ui/handler/touch_zoom_rotate.js index 7d33cb5044a..ff5a0a30a7b 100644 --- a/src/ui/handler/touch_zoom_rotate.js +++ b/src/ui/handler/touch_zoom_rotate.js @@ -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'; } } diff --git a/test/unit/ui/handler/touch_zoom_rotate.test.js b/test/unit/ui/handler/touch_zoom_rotate.test.js index 6789f1c9210..d2e96eccc08 100644 --- a/test/unit/ui/handler/touch_zoom_rotate.test.js +++ b/test/unit/ui/handler/touch_zoom_rotate.test.js @@ -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(); +});