use offset when animating transform to avoid dividing by zero

This commit is contained in:
Vladimir Agafonkin 2014-01-16 17:34:26 +02:00
parent c1b2c5c37c
commit de4910f407
3 changed files with 9 additions and 6 deletions

View File

@ -502,7 +502,10 @@ L.GridLayer = L.Layer.extend({
_animateZoom: function (e) { _animateZoom: function (e) {
// avoid stacking transforms by calculating cumulating translate/scale sequence // avoid stacking transforms by calculating cumulating translate/scale sequence
this._translate = this._prevTranslate.multiplyBy(e.scale).add(e.origin.multiplyBy(1 - e.scale)).round(); this._translate = this._prevTranslate.multiplyBy(e.scale)
.add(e.origin.multiplyBy(1 - e.scale))
.add(e.offset).round();
this._scale = this._prevScale * e.scale; this._scale = this._prevScale * e.scale;
L.DomUtil.setTransform(this._bgBuffer, this._translate, this._scale); L.DomUtil.setTransform(this._bgBuffer, this._translate, this._scale);

View File

@ -45,7 +45,7 @@ L.Renderer = L.Layer.extend({
_animateZoom: function (e) { _animateZoom: function (e) {
var origin = e.origin.subtract(this._map._getCenterLayerPoint()), var origin = e.origin.subtract(this._map._getCenterLayerPoint()),
offset = this._bounds.min.add(origin.multiplyBy(1 - e.scale)); offset = this._bounds.min.add(origin.multiplyBy(1 - e.scale)).add(e.offset).round();
L.DomUtil.setTransform(this._container, offset, e.scale); L.DomUtil.setTransform(this._container, offset, e.scale);
}, },

View File

@ -78,14 +78,14 @@ L.Map.include(!zoomAnimated ? {} : {
L.DomUtil.addClass(this._mapPane, 'leaflet-zoom-anim'); L.DomUtil.addClass(this._mapPane, 'leaflet-zoom-anim');
} }
var scale = this.getZoomScale(zoom), var centerOffset = this._getCenterOffset(center);
origin = this._getCenterLayerPoint().add(this._getCenterOffset(center)._divideBy(1 - 1 / scale));
this.fire('zoomanim', { this.fire('zoomanim', {
center: center, center: center,
zoom: zoom, zoom: zoom,
origin: origin, scale: this.getZoomScale(zoom),
scale: scale origin: this._getCenterLayerPoint().add(centerOffset),
offset: centerOffset.multiplyBy(-1)
}); });
}, },