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

View File

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