diff --git a/lib/OpenLayers/Control/ZoomBox.js b/lib/OpenLayers/Control/ZoomBox.js index 217a90a434..f8cea39bed 100644 --- a/lib/OpenLayers/Control/ZoomBox.js +++ b/lib/OpenLayers/Control/ZoomBox.js @@ -83,8 +83,8 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, maxXY.lon, maxXY.lat); } else { - var pixWidth = Math.abs(position.right-position.left); - var pixHeight = Math.abs(position.top-position.bottom); + var pixWidth = position.right - position.left; + var pixHeight = position.bottom - position.top; var zoomFactor = Math.min((this.map.size.h / pixHeight), (this.map.size.w / pixWidth)); var extent = this.map.getExtent(); @@ -103,10 +103,10 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { oldRes = this.map.getResolution(), newRes = this.map.getResolutionForZoom(zoom), zoomOriginPx = { - x: targetCenterPx.x + - (targetCenterPx.x - centerPx.x) * newRes / oldRes, - y: targetCenterPx.y + - (targetCenterPx.y - centerPx.y) * newRes / oldRes + x: (oldRes * targetCenterPx.x - newRes * centerPx.x) / + (oldRes - newRes), + y: (oldRes * targetCenterPx.y - newRes * centerPx.y) / + (oldRes - newRes) }; this.map.zoomTo(zoom, zoomOriginPx); if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){