From f6a123667c0c5cb0d0ec9a08aaeb723a15053aa3 Mon Sep 17 00:00:00 2001 From: javi Date: Fri, 21 Mar 2014 12:47:56 +0100 Subject: [PATCH] added zoom animation --- lib/torque/leaflet/canvas_layer.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/torque/leaflet/canvas_layer.js b/lib/torque/leaflet/canvas_layer.js index f0889ad..9188546 100644 --- a/lib/torque/leaflet/canvas_layer.js +++ b/lib/torque/leaflet/canvas_layer.js @@ -104,24 +104,25 @@ L.CanvasLayer = L.Class.extend({ // hide original this._canvas.style.display = 'none'; back.style.display = 'block'; + var map = this._map; + var scale = map.getZoomScale(e.zoom); + var newCenter = map._latLngToNewLayerPoint(map.getCenter(), e.zoom, e.center); + var oldCenter = map._latLngToNewLayerPoint(e.center, e.zoom, e.center); + var origin = { + x: newCenter.x - oldCenter.x, + y: newCenter.y - oldCenter.y + }; - var bg = back, - transform = L.DomUtil.TRANSFORM, - initialTransform = e.delta ? L.DomUtil.getTranslateString(e.delta) : bg.style[transform], - scaleStr = L.DomUtil.getScaleString(e.scale, e.origin); - - //scaleStr = ' scale(' + e.scale + ') '; - bg.style[transform] = scaleStr; - /*bg.style[transform] = e.backwards ? - scaleStr + ' ' + initialTransform : - initialTransform + ' ' + scaleStr; - */ + var bg = back; + var transform = L.DomUtil.TRANSFORM; + bg.style[transform] = L.DomUtil.getTranslateString(origin) + ' scale(' + e.scale + ') '; }, _endZoomAnim: function () { this._animating = false; - //this._canvas.style.visibility = 'block'; + this._canvas.style.display = 'block'; + this._backCanvas.style.display = 'none'; }, getCanvas: function() {