diff --git a/js/ui/camera.js b/js/ui/camera.js index b19af10cd2d..f8e77e8b768 100644 --- a/js/ui/camera.js +++ b/js/ui/camera.js @@ -38,6 +38,7 @@ class Camera extends Evented { constructor(transform, options) { super(); + this.moving = false; this.transform = transform; this._bearingSnap = options.bearingSnap; } @@ -469,6 +470,7 @@ class Camera extends Evented { } if (!options.noMoveStart) { + this.moving = true; this.fire('movestart', eventData); } if (this.zooming) { @@ -515,6 +517,7 @@ class Camera extends Evented { _easeToEnd(eventData) { const wasZooming = this.zooming; + this.moving = false; this.zooming = false; this.rotating = false; this.pitching = false; @@ -695,6 +698,7 @@ class Camera extends Evented { options.duration = 1000 * S / V; } + this.moving = true; this.zooming = true; if (startBearing !== bearing) this.rotating = true; if (startPitch !== pitch) this.pitching = true; @@ -727,6 +731,7 @@ class Camera extends Evented { this.fire('pitch', eventData); } }, function() { + this.moving = false; this.zooming = false; this.rotating = false; this.pitching = false; @@ -742,6 +747,16 @@ class Camera extends Evented { return !!this._abortFn; } + /** + * Returns a Boolean indicating whether the camera is moving. + * + * @memberof Map# + * @returns {boolean} A Boolean indicating whether the camera is moving. + */ + isMoving() { + return this.moving; + } + /** * Stops any animated transition underway. * diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 49bb25e6381..6e083c95e21 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -1155,6 +1155,23 @@ test('Map', (t) => { }); }); + t.test('Map#isMoving', (t) => { + t.plan(3); + const map = createMap(); + + t.equal(map.isMoving(), false, 'false before moving'); + + map.on('movestart', () => { + t.equal(map.isMoving(), true, 'true on movestart'); + }); + + map.on('moveend', () => { + t.equal(map.isMoving(), false, 'false on moveend'); + }); + + map.zoomTo(5, { duration: 0 }); + }); + t.end(); });