Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "Map#isMoving" method #2792 #3941

Merged
merged 3 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions js/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Camera extends Evented {

constructor(transform, options) {
super();
this.moving = false;
this.transform = transform;
this._bearingSnap = options.bearingSnap;
}
Expand Down Expand Up @@ -469,6 +470,7 @@ class Camera extends Evented {
}

if (!options.noMoveStart) {
this.moving = true;
this.fire('movestart', eventData);
}
if (this.zooming) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.
*
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, '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();
});

Expand Down