From 758679ab69be2530f32f831d2624d88888a144ef Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 10 Jan 2014 16:05:58 +0200 Subject: [PATCH] add DomUtil.setTransform for translate+scale ops --- src/dom/DomUtil.js | 6 +++++- src/layer/ImageOverlay.js | 2 +- src/layer/tile/GridLayer.js | 4 ++-- src/layer/vector/Renderer.js | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js index 93c52710..de6b91f2 100644 --- a/src/dom/DomUtil.js +++ b/src/dom/DomUtil.js @@ -141,6 +141,10 @@ L.DomUtil = { point.y + 'px' + (is3d ? ',0)' : ')'); }, + setTransform: function (el, point, scale) { + el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point) + (scale ? ' scale(' + scale + ')' : ''); + }, + getScaleString: function (scale, origin) { return L.DomUtil.getTranslateString(origin.multiplyBy(1 - scale)) + ' scale(' + scale + ') '; }, @@ -151,7 +155,7 @@ L.DomUtil = { el._leaflet_pos = point; if (!disable3D && L.Browser.any3d) { - el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point); + L.DomUtil.setTransform(el, point); } else { el.style.left = point.x + 'px'; el.style.top = point.y + 'px'; diff --git a/src/layer/ImageOverlay.js b/src/layer/ImageOverlay.js index c8ef6550..7281740a 100644 --- a/src/layer/ImageOverlay.js +++ b/src/layer/ImageOverlay.js @@ -92,7 +92,7 @@ L.ImageOverlay = L.Layer.extend({ size = map._latLngToNewLayerPoint(this._bounds.getSouthEast(), e.zoom, e.center)._subtract(topLeft), origin = topLeft._add(size._multiplyBy((1 - 1 / scale) / 2)); - image.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(origin) + ' scale(' + scale + ') '; + L.DomUtil.setTransform(image, origin, scale); }, _reset: function () { diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index 26d26621..faaffeac 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -498,7 +498,7 @@ L.GridLayer = L.Layer.extend({ if (map && !map._animatingZoom && !map.touchZoom._zooming) { this._bgBuffer.innerHTML = ''; - this._bgBuffer.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(); + L.DomUtil.setTransform(this._bgBuffer); } }, @@ -514,7 +514,7 @@ L.GridLayer = L.Layer.extend({ // prepare the buffer to become the front tile pane bg.style.visibility = 'hidden'; - bg.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(); + L.DomUtil.setTransform(bg); // switch out the current layer to be the new bg layer (and vice-versa) this._tileContainer = bg; diff --git a/src/layer/vector/Renderer.js b/src/layer/vector/Renderer.js index 4ea6acb4..e8f5c7e7 100644 --- a/src/layer/vector/Renderer.js +++ b/src/layer/vector/Renderer.js @@ -47,7 +47,7 @@ L.Renderer = L.Layer.extend({ var scale = this._map.getZoomScale(e.zoom), offset = this._map._getCenterOffset(e.center)._multiplyBy(-scale)._add(this._bounds.min); - this._container.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(offset) + ' scale(' + scale + ') '; + L.DomUtil.setTransform(this._container, offset, scale); }, _update: function () {