From 97598d42416d0480133a3f13f65ec6137828f57d Mon Sep 17 00:00:00 2001 From: Dave Leaver Date: Thu, 20 Mar 2014 11:40:15 +1300 Subject: [PATCH] Move animated zoom stopping in to the place it belongs --- src/map/Map.js | 29 ++--------------------------- src/map/anim/Map.ZoomAnimation.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index 0224039b..dec0a0c0 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -201,6 +201,7 @@ L.Map = L.Evented.extend({ //zoomPan L.Util.cancelAnimFrame(this._zoomPanFrame); + //TODO: Need to fire zoomend if this was what was going on //PosAnimation if (this._panAnim && this._panAnim._inProgress) { @@ -210,34 +211,8 @@ L.Map = L.Evented.extend({ //zoomAnimation if (this._animatingZoom) { - //Calculate _animateToZoom and _animateToCenter - var regex = /([-+]?(?:\d*\.)?\d+)\D*, ([-+]?(?:\d*\.)?\d+)\D*, ([-+]?(?:\d*\.)?\d+)\D*\)/; - var style = window.getComputedStyle(this._proxy._el); - var matches = style[L.DomUtil.TRANSFORM].match(regex); - //Assuming this works! - - //debugger; - this._animateToZoom = this.getScaleZoom(parseFloat(matches[1]), 1); - var px = L.point(matches[2], matches[3]); - this._animateToCenter = this.unproject(px, this._animateToZoom); - - console.log('stop', this._animateToCenter); - //this._animateToCenter.lat = parseFloat(matches[2]); - //this._animateToCenter.lng = parseFloat(matches[3]); - - //L.Util.falseFn(map._panes.mapPane.offsetWidth); - - this._onZoomTransitionEnd(); - //L.Util.falseFn(map._panes.mapPane.offsetWidth); - - //Something like _onZoomTransitionEnd, but not quite, we don't want the _resetView call - - //Or if we set _animateToCenter and _animateToZoom then we can just call it + this._stopAnimatedZoom(); } - - //TODO do a reset view - - }, // TODO handler.addTo diff --git a/src/map/anim/Map.ZoomAnimation.js b/src/map/anim/Map.ZoomAnimation.js index ac29caa2..ab8d39ac 100644 --- a/src/map/anim/Map.ZoomAnimation.js +++ b/src/map/anim/Map.ZoomAnimation.js @@ -87,6 +87,20 @@ L.Map.include(!zoomAnimated ? {} : { }); }, + _stopAnimatedZoom: function () { + + //Extract zoom and translate from the matrix + var regex = /([-+]?(?:\d*\.)?\d+)\D*, ([-+]?(?:\d*\.)?\d+)\D*, ([-+]?(?:\d*\.)?\d+)\D*\)/, + style = window.getComputedStyle(this._proxy._el), + matches = style[L.DomUtil.TRANSFORM].match(regex), + px = L.point(matches[2], matches[3]); + + //Replace the animation end variables with the current zoom/center + this._animateToZoom = this.getScaleZoom(parseFloat(matches[1]), 1); + this._animateToCenter = this.unproject(px, this._animateToZoom); + + this._onZoomTransitionEnd(); + }, _onZoomTransitionEnd: function () { this._animatingZoom = false;