OpenLayers OpenLayers

Changeset 1558

Show
Ignore:
Timestamp:
10/04/06 10:05:34 (2 years ago)
Author:
crschmidt
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/BaseTypes.js

    r1533 r1558  
    365365    * @type String 
    366366    */ 
    367     toBBOX:function() { 
    368         return (this.left + "," + this.bottom + "," 
    369                 + this.right + "," + this.top); 
     367    toBBOX:function(power) { 
     368        var mult; 
     369        if (power) { 
     370            mult = Math.pow(10,power); 
     371        } else {  
     372            mult = Math.pow(10,6);  
     373        }   
     374        return (Math.round(this.left*mult)/mult + "," +  
     375               Math.round(this.bottom*mult)/mult + "," +  
     376               Math.round(this.right*mult)/mult + "," +  
     377               Math.round(this.top*mult)/mult); 
    370378    }, 
    371379     
  • trunk/openlayers/tests/test_Bounds.html

    r1533 r1558  
    4242 
    4343     function test_02_Bounds_toBBOX(t) { 
    44          t.plan( 1 ); 
     44         t.plan( 5 ); 
    4545         bounds = new OpenLayers.Bounds(1,2,3,4); 
    4646         t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." ); 
     47         bounds = new OpenLayers.Bounds(1.00000001,2,3,4); 
     48         t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() rounds off small differences." ); 
     49         bounds = new OpenLayers.Bounds(1.00000001,2.5,3,4); 
     50         t.eq( bounds.toBBOX(), "1,2.5,3,4", "toBBOX() returns correct value. for a half number" ); 
     51         bounds = new OpenLayers.Bounds(1,2.5555555,3,4); 
     52         t.eq( bounds.toBBOX(), "1,2.555556,3,4", "toBBOX() rounds to correct value." ); 
     53         bounds = new OpenLayers.Bounds(1,2.5555555,3,4); 
     54         t.eq( bounds.toBBOX(1), "1,2.6,3,4", "toBBOX() rounds to correct value with power provided." ); 
     55         bounds = new OpenLayers.Bounds(1,2.5555555,3,4); 
    4756     } 
    4857