Add rounding support to the default toBBOX() call. Now, toBBOX() will by
default return values which are rounded to 6 decimal places. If you wish more or less accuracy, you can change it by passing a numeric argument with the accuracy you want to toBBOX(), and that accuracy will be used instead. Updated tests to test rounding to various levels. This functionality should help prevent different browsers from hitting different caches. At the equator, this rounding difference is only 4", and smaller as you head towards the poles. git-svn-id: http://svn.openlayers.org/trunk/openlayers@1558 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -364,9 +364,17 @@ OpenLayers.Bounds.prototype = {
|
||||
* (ex. <i>"5,42,10,45"</i>)
|
||||
* @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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user