add fromZoom arg to Map getZoomScale and getScaleZoom

This commit is contained in:
Vladimir Agafonkin 2014-01-20 20:27:58 +02:00
parent 1b8f68d806
commit dc04b9dbe2
3 changed files with 13 additions and 9 deletions

View File

@ -102,7 +102,7 @@ L.TileLayer = L.GridLayer.extend({
// increase tile size when overscaling // increase tile size when overscaling
return zoomN && zoom > zoomN ? return zoomN && zoom > zoomN ?
Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * options.tileSize) : Math.round(map.getZoomScale(zoomN, zoom) * options.tileSize) :
options.tileSize; options.tileSize;
}, },

View File

@ -348,13 +348,15 @@ L.Map = L.Evented.extend({
// TODO replace with universal implementation after refactoring projections // TODO replace with universal implementation after refactoring projections
getZoomScale: function (toZoom) { getZoomScale: function (toZoom, fromZoom) {
var crs = this.options.crs; var crs = this.options.crs;
return crs.scale(toZoom) / crs.scale(this._zoom); fromZoom = fromZoom === undefined ? this._zoom : fromZoom;
return crs.scale(toZoom) / crs.scale(fromZoom);
}, },
getScaleZoom: function (scale) { getScaleZoom: function (scale, fromZoom) {
return this._zoom + (Math.log(scale) / Math.LN2); fromZoom = fromZoom === undefined ? this._zoom : fromZoom;
return fromZoom + (Math.log(scale) / Math.LN2);
}, },

View File

@ -6,8 +6,9 @@ L.Map.include({
to = this.project(center), to = this.project(center),
u1 = to.distanceTo(from), u1 = to.distanceTo(from),
size = this.getSize(), size = this.getSize(),
zoom = this._zoom,
w0 = Math.max(size.x, size.y), w0 = Math.max(size.x, size.y),
w1 = w0 * this.getZoomScale(this._zoom) / this.getZoomScale(targetZoom), w1 = w0 * this.getZoomScale(targetZoom, zoom),
rho = 1.42, rho = 1.42,
rho2 = rho * rho; rho2 = rho * rho;
@ -26,10 +27,11 @@ L.Map.include({
function u(s) { return w0 * (cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2; } function u(s) { return w0 * (cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2; }
function step(s) { function step(s) {
var center = this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1))), var center = this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1)), targetZoom),
zoom = this.getScaleZoom(this.getZoomScale(this._zoom) * w0 / w(s)); newZoom = this.getScaleZoom(w0 / w(s), zoom);
this._animateZoom(center, zoom); this._resetView(center, newZoom, true, true);
this._animateZoom(center, newZoom);
} }
function easeOut(t) { return 1 - Math.pow(1 - t, 2); } function easeOut(t) { return 1 - Math.pow(1 - t, 2); }