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}.
This commit is contained in:
committed by
Bart van den Eijnden
parent
1cf69634cf
commit
8cccbfb189
@@ -101,14 +101,18 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
centerPx = {x: size.w / 2, y: size.h / 2},
|
centerPx = {x: size.w / 2, y: size.h / 2},
|
||||||
zoom = this.map.getZoomForExtent(bounds),
|
zoom = this.map.getZoomForExtent(bounds),
|
||||||
oldRes = this.map.getResolution(),
|
oldRes = this.map.getResolution(),
|
||||||
newRes = this.map.getResolutionForZoom(zoom),
|
newRes = this.map.getResolutionForZoom(zoom);
|
||||||
zoomOriginPx = {
|
if (oldRes == newRes) {
|
||||||
|
this.map.setCenter(this.map.getLonLatFromPixel(targetCenterPx));
|
||||||
|
} else {
|
||||||
|
var zoomOriginPx = {
|
||||||
x: (oldRes * targetCenterPx.x - newRes * centerPx.x) /
|
x: (oldRes * targetCenterPx.x - newRes * centerPx.x) /
|
||||||
(oldRes - newRes),
|
(oldRes - newRes),
|
||||||
y: (oldRes * targetCenterPx.y - newRes * centerPx.y) /
|
y: (oldRes * targetCenterPx.y - newRes * centerPx.y) /
|
||||||
(oldRes - newRes)
|
(oldRes - newRes)
|
||||||
};
|
};
|
||||||
this.map.zoomTo(zoom, zoomOriginPx);
|
this.map.zoomTo(zoom, zoomOriginPx);
|
||||||
|
}
|
||||||
if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){
|
if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){
|
||||||
this.map.zoomTo(lastZoom + (this.out ? -1 : 1));
|
this.map.zoomTo(lastZoom + (this.out ? -1 : 1));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user