From 60df92045202ea8517b110b7852707ab18c313fe Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 8 Mar 2015 12:21:43 +0100 Subject: [PATCH] Add optional callback to map.flyTo --- spec/suites/map/MapSpec.js | 20 ++++++++++++++++++++ src/map/anim/Map.FlyTo.js | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index e7261ce0..b4f4c8de 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -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); + }); + + }); + }); diff --git a/src/map/anim/Map.FlyTo.js b/src/map/anim/Map.FlyTo.js index 81128f1a..44e12b25 100644 --- a/src/map/anim/Map.FlyTo.js +++ b/src/map/anim/Map.FlyTo.js @@ -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(); + } } }