From c0158855ddfa34f4706c5190e6d3da3972e1b901 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Mon, 12 Feb 2018 09:39:44 -0800 Subject: [PATCH] add Map#isZooming method (#6128) * add Map#isZooming method * initialize Camera#zooming --- src/ui/camera.js | 11 +++++++++++ test/unit/ui/map.test.js | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/ui/camera.js b/src/ui/camera.js index 9ff26fe1c73..bcd3b5ae708 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -83,6 +83,7 @@ class Camera extends Evented { constructor(transform: Transform, options: {bearingSnap: number}) { super(); this.moving = false; + this.zooming = false; this.transform = transform; this._bearingSnap = options.bearingSnap; } @@ -858,6 +859,16 @@ class Camera extends Evented { return this.moving; } + /** + * Returns a Boolean indicating whether the camera is zooming. + * + * @memberof Map# + * @returns A Boolean indicating whether the camera is zooming. + */ + isZooming(): boolean { + return this.zooming; + } + /** * Stops any animated transition underway. * diff --git a/test/unit/ui/map.test.js b/test/unit/ui/map.test.js index f75452d9797..ea58a00304d 100755 --- a/test/unit/ui/map.test.js +++ b/test/unit/ui/map.test.js @@ -1268,6 +1268,23 @@ test('Map', (t) => { map.zoomTo(5, { duration: 0 }); }); + t.test('Map#isZooming', (t) => { + t.plan(3); + const map = createMap(); + + t.equal(map.isZooming(), false, 'false before zooming'); + + map.on('zoomstart', () => { + t.equal(map.isZooming(), true, 'true on zoomstart'); + }); + + map.on('zoomend', () => { + t.equal(map.isZooming(), false, 'false on zoomend'); + }); + + map.zoomTo(5, { duration: 0 }); + }); + t.end(); });