diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index 06dc5e1d2f..e43e813227 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -623,20 +623,21 @@ OpenLayers.Bounds = OpenLayers.Class({ if (maxExtent) { var width = maxExtent.getWidth(); - //shift right? - while ( newBounds.left < maxExtent.left && - (newBounds.right - rightTolerance) <= maxExtent.left ) { + //shift right? + while (newBounds.left < maxExtent.left && + newBounds.right - rightTolerance <= maxExtent.left ) { newBounds = newBounds.add(width, 0); - } + } - //shift left? - while ( (newBounds.left + leftTolerance) >= maxExtent.right && + //shift left? + while (newBounds.left + leftTolerance >= maxExtent.right && newBounds.right > maxExtent.right ) { newBounds = newBounds.add(-width, 0); - } + } - // crosses right? force left - if (newBounds.left < maxExtent.right && newBounds.right > maxExtent.right) { + // crosses right? force left + if (newBounds.left + leftTolerance < maxExtent.right && + newBounds.right - rightTolerance > maxExtent.right) { newBounds = newBounds.add(-width, 0); } }