From 9a13a2137aeeaf38fbf2e3f9f5618c99632fa229 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Tue, 10 Jan 2017 22:47:27 +0300 Subject: [PATCH] add "Map#isMoving" method #2792 --- js/ui/map.js | 14 ++++++++++++++ test/js/ui/map.test.js | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/js/ui/map.js b/js/ui/map.js index 12837508269..19934d2b4af 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -134,6 +134,7 @@ class Map extends Camera { const transform = new Transform(options.minZoom, options.maxZoom, options.renderWorldCopies); super(transform, options); + this._isMoving = false; this._interactive = options.interactive; this._failIfMajorPerformanceCaveat = options.failIfMajorPerformanceCaveat; this._preserveDrawingBuffer = options.preserveDrawingBuffer; @@ -169,9 +170,13 @@ class Map extends Camera { this.on('move', this._update.bind(this, false)); this.on('zoom', this._update.bind(this, true)); + this.on('movestart', () => { + this._isMoving = true; + }); this.on('moveend', () => { this.animationLoop.set(300); // text fading this._rerender(); + this._isMoving = false; }); if (typeof window !== 'undefined') { @@ -1215,6 +1220,15 @@ class Map extends Camera { } } + /** + * Returns a Boolean indicating whether the map is moving. + * + * @returns {boolean} A Boolean indicating whether the map is moving. + */ + isMoving() { + return this._isMoving; + } + /** * Gets and sets a Boolean indicating whether the map will render an outline * around each tile. These tile boundaries are useful for debugging. diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 49bb25e6381..a99e71b5371 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); + + map.on('movestart', () => { + t.equal(map.isMoving(), true); + }); + + map.on('moveend', () => { + t.equal(map.isMoving(), false); + }); + + map.zoomTo(5, { duration: 0 }); + }); + t.end(); });