diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index 7ea7f3bcda..e79454f9d1 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -219,6 +219,48 @@ OpenLayers.Bounds = OpenLayers.Class({ (this.bottom + this.top) / 2); }, + /** + * Method: scale + * Scales the bounds around a pixel or lonlat. Note that the new + * bounds may return non-integer properties, even if a pixel + * is passed. + * + * Parameters: + * ratio - {Float} + * origin - { or } + * Default is center. + * + * Returns: + * {} A new bounds that is scaled by ratio + * from origin. + */ + + scale: function(ratio, origin){ + if(origin == null){ + origin = this.getCenterLonLat(); + } + + var bounds = []; + + var origx,origy; + + // get origin coordinates + if(origin.CLASS_NAME == "OpenLayers.LonLat"){ + origx = origin.lon; + origy = origin.lat; + } else { + origx = origin.x; + origy = origin.y; + } + + var left = (this.left - origx) * ratio + origx; + var bottom = (this.bottom - origy) * ratio + origy; + var right = (this.right - origx) * ratio + origx; + var top = (this.top - origy) * ratio + origy; + + return new OpenLayers.Bounds(left, bottom, right, top); + }, + /** * APIMethod: add * diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 159bd2994e..1890b94dc8 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -196,6 +196,13 @@ OpenLayers.Map = OpenLayers.Class({ */ zoom: 0, + /** + * Property: panRatio + * {Float} The ratio of the current extent within + * which panning will tween. + */ + panRatio: 1.5, + /** * Property: viewRequestID * {String} Used to store a unique identifier that changes when the map @@ -1368,7 +1375,7 @@ OpenLayers.Map = OpenLayers.Class({ * lonlat - {} */ panTo: function(lonlat) { - if (this.panMethod && this.getExtent().containsLonLat(lonlat)) { + if (this.panMethod && this.getExtent().scale(this.panRatio).containsLonLat(lonlat)) { if (!this.panTween) { this.panTween = new OpenLayers.Tween(this.panMethod); } diff --git a/tests/BaseTypes/Bounds.html b/tests/BaseTypes/Bounds.html index f77852703e..55c21874ed 100644 --- a/tests/BaseTypes/Bounds.html +++ b/tests/BaseTypes/Bounds.html @@ -557,6 +557,25 @@ t.ok(bounds == null, "returns null on erroneous add operation (null y)"); } + function test_Bounds_scale(t) { + t.plan(3); + + origBounds = new OpenLayers.Bounds(1,2,3,4); + bounds = origBounds.scale(2); + var b = new OpenLayers.Bounds(0,1,4,5); + t.ok(bounds.equals(b), "Bounds scale correctly with default origin at center") + + var origin = new OpenLayers.Pixel(0,1); + bounds = origBounds.scale(2,origin); + b = new OpenLayers.Bounds(2,3,6,7); + t.ok(bounds.equals(b), "Bounds scale correctly with offset origin"); + + origin = new OpenLayers.Pixel(5,1); + bounds = bounds.scale(2, origin); + b = new OpenLayers.Bounds(-1, 5, 7, 13); + t.ok(bounds.equals(b), "Bounds scale correctly with offset origin"); + + }