Skip to content

Commit

Permalink
add "Map#isMoving" method mapbox#2792
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Jan 10, 2017
1 parent 8780088 commit 9a13a21
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions test/js/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 9a13a21

Please sign in to comment.