Implement options in L.Map.flyTo()

This commit is contained in:
Iván Sánchez Ortega 2015-04-23 09:18:59 +02:00
parent 578247150c
commit c3575be344
2 changed files with 12 additions and 3 deletions

View File

@ -27,6 +27,7 @@
<button id="kyiv">Kyiv</button> --> <button id="kyiv">Kyiv</button> -->
<button id="dc">DC</button> <button id="dc">DC</button>
<button id="sf">SF</button> <button id="sf">SF</button>
<button id="trd">TRD</button>
<button id="stop">stop</button> <button id="stop">stop</button>
</div> </div>
@ -36,6 +37,7 @@
london = [51.51, -0.12], london = [51.51, -0.12],
sf = [37.77, -122.42], sf = [37.77, -122.42],
dc = [38.91, -77.04]; dc = [38.91, -77.04];
trd = [63.41, 10.41];
var map = L.map('map').setView(dc, 10); var map = L.map('map').setView(dc, 10);
@ -51,6 +53,7 @@
document.getElementById('dc').onclick = function () { map.flyTo(dc, 10); }; document.getElementById('dc').onclick = function () { map.flyTo(dc, 10); };
document.getElementById('sf').onclick = function () { map.flyTo(sf, 10); }; document.getElementById('sf').onclick = function () { map.flyTo(sf, 10); };
document.getElementById('trd').onclick = function () { map.flyTo(trd, 10, {duration: 20}); };
document.getElementById('stop').onclick = function () { map.stop(); }; document.getElementById('stop').onclick = function () { map.stop(); };
// document.getElementById('london').onclick = function () { map.flyTo(london); }; // document.getElementById('london').onclick = function () { map.flyTo(london); };
// document.getElementById('kyiv').onclick = function () { map.flyTo(kyiv); }; // document.getElementById('kyiv').onclick = function () { map.flyTo(kyiv); };

View File

@ -1,6 +1,11 @@
L.Map.include({ L.Map.include({
flyTo: function (targetCenter, targetZoom) { flyTo: function (targetCenter, targetZoom, options) {
options = options || {};
if (options.animate === false) {
return this.setView(targetCenter, targetZoom, options);
}
this.stop(); this.stop();
@ -36,7 +41,7 @@ L.Map.include({
var start = Date.now(), var start = Date.now(),
S = (r(1) - r0) / rho, S = (r(1) - r0) / rho,
duration = 1000 * S * 0.8; duration = options.duration ? 1000 * options.duration : 1000 * S * 0.8;
function frame() { function frame() {
var t = (Date.now() - start) / duration, var t = (Date.now() - start) / duration,
@ -56,10 +61,11 @@ L.Map.include({
this.fire('zoomstart'); this.fire('zoomstart');
frame.call(this); frame.call(this);
return this;
}, },
flyToBounds: function(bounds, options) { flyToBounds: function(bounds, options) {
var target = this._getBoundsCenterZoom(bounds, options); var target = this._getBoundsCenterZoom(bounds, options);
return this.flyTo(target.center, target.zoom); return this.flyTo(target.center, target.zoom, options);
} }
}); });