diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 7ac2c5c066..d42ae9e962 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -364,9 +364,17 @@ OpenLayers.Bounds.prototype = { * (ex. "5,42,10,45") * @type String */ - toBBOX:function() { - return (this.left + "," + this.bottom + "," - + this.right + "," + this.top); + toBBOX:function(power) { + var mult; + if (power) { + mult = Math.pow(10,power); + } else { + mult = Math.pow(10,6); + } + return (Math.round(this.left*mult)/mult + "," + + Math.round(this.bottom*mult)/mult + "," + + Math.round(this.right*mult)/mult + "," + + Math.round(this.top*mult)/mult); }, /** diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index cc5d84af4b..947febdea7 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -41,9 +41,18 @@ } function test_02_Bounds_toBBOX(t) { - t.plan( 1 ); + t.plan( 5 ); bounds = new OpenLayers.Bounds(1,2,3,4); t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." ); + bounds = new OpenLayers.Bounds(1.00000001,2,3,4); + t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() rounds off small differences." ); + bounds = new OpenLayers.Bounds(1.00000001,2.5,3,4); + t.eq( bounds.toBBOX(), "1,2.5,3,4", "toBBOX() returns correct value. for a half number" ); + bounds = new OpenLayers.Bounds(1,2.5555555,3,4); + t.eq( bounds.toBBOX(), "1,2.555556,3,4", "toBBOX() rounds to correct value." ); + bounds = new OpenLayers.Bounds(1,2.5555555,3,4); + t.eq( bounds.toBBOX(1), "1,2.6,3,4", "toBBOX() rounds to correct value with power provided." ); + bounds = new OpenLayers.Bounds(1,2.5555555,3,4); } function test_03_Bounds_toString(t) {