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(); +});