Add optional callback to map.flyTo

This commit is contained in:
Yohan Boniface 2015-03-08 12:21:43 +01:00
parent a92c8a3c21
commit 60df920452
2 changed files with 24 additions and 1 deletions

View File

@ -570,4 +570,24 @@ describe("Map", function () {
expect(spy.called).to.be.ok();
});
});
describe('#flyTo', function () {
it('move to requested center and zoom, and call callback once', function (done) {
var spy = sinon.spy(),
newCenter = new L.LatLng(10, 11),
newZoom = 12,
callback = function () {
expect(map.getCenter()).to.eql(newCenter);
expect(map.getZoom()).to.eql(newZoom);
spy();
expect(spy.calledOnce).to.be.ok();
done();
};
map.setView([0, 0], 0);
map.flyTo(newCenter, newZoom, callback);
});
});
});

View File

@ -1,6 +1,6 @@
L.Map.include({
flyTo: function (targetCenter, targetZoom) {
flyTo: function (targetCenter, targetZoom, callback) {
this.stop();
@ -51,6 +51,9 @@ L.Map.include({
} else {
this._resetView(targetCenter, targetZoom, true, true);
if (callback) {
callback();
}
}
}