From 8cccbfb189ad89d646ee1115881846bec5012a25 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 6 Jun 2013 00:06:25 +0200 Subject: [PATCH] Protect ZoomBox from division by zero When the map is at the highest zoom level, the old and the current resolution will be the same. This would cause a division by zero, which the JavaScript engine does not recognize as such. So we have to protect zoomOriginPx from becoming {x: Infinity, y: Infinity}. --- lib/OpenLayers/Control/ZoomBox.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Control/ZoomBox.js b/lib/OpenLayers/Control/ZoomBox.js index f8cea39bed..9d4b2da00a 100644 --- a/lib/OpenLayers/Control/ZoomBox.js +++ b/lib/OpenLayers/Control/ZoomBox.js @@ -101,14 +101,18 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { centerPx = {x: size.w / 2, y: size.h / 2}, zoom = this.map.getZoomForExtent(bounds), oldRes = this.map.getResolution(), - newRes = this.map.getResolutionForZoom(zoom), - zoomOriginPx = { + newRes = this.map.getResolutionForZoom(zoom); + if (oldRes == newRes) { + this.map.setCenter(this.map.getLonLatFromPixel(targetCenterPx)); + } else { + var zoomOriginPx = { x: (oldRes * targetCenterPx.x - newRes * centerPx.x) / (oldRes - newRes), y: (oldRes * targetCenterPx.y - newRes * centerPx.y) / (oldRes - newRes) }; - this.map.zoomTo(zoom, zoomOriginPx); + this.map.zoomTo(zoom, zoomOriginPx); + } if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){ this.map.zoomTo(lastZoom + (this.out ? -1 : 1)); }