[OpenLayers-Commits] r11035 - in trunk/openlayers: lib/OpenLayers/BaseTypes tests/BaseTypes

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon Jan 17 04:18:21 EST 2011


Author: ahocevar
Date: 2011-01-17 01:18:21 -0800 (Mon, 17 Jan 2011)
New Revision: 11035

Modified:
   trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js
   trunk/openlayers/tests/BaseTypes/Bounds.html
Log:
Giving fromArray and fromString a reverseAxisOrder option. r=erilem (closes #3014)


Modified: trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js	2011-01-14 16:13:10 UTC (rev 11034)
+++ trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js	2011-01-17 09:18:21 UTC (rev 11035)
@@ -615,14 +615,15 @@
  * 
  * Parameters: 
  * str - {String}Comma-separated bounds string. (ex. <i>"5,42,10,45"</i>)
+ * reverseAxisOrder - {Boolean} Does the string use reverse axis order?
  * 
  * Returns:
  * {<OpenLayers.Bounds>} New bounds object built from the 
  *                       passed-in String.
  */
-OpenLayers.Bounds.fromString = function(str) {
+OpenLayers.Bounds.fromString = function(str, reverseAxisOrder) {
     var bounds = str.split(",");
-    return OpenLayers.Bounds.fromArray(bounds);
+    return OpenLayers.Bounds.fromArray(bounds, reverseAxisOrder);
 };
 
 /** 
@@ -632,12 +633,18 @@
  * 
  * Parameters:
  * bbox - {Array(Float)} Array of bounds values (ex. <i>[5,42,10,45]</i>)
+ * reverseAxisOrder - {Boolean} Does the array use reverse axis order?
  *
  * Returns:
  * {<OpenLayers.Bounds>} New bounds object built from the passed-in Array.
  */
-OpenLayers.Bounds.fromArray = function(bbox) {
-    return new OpenLayers.Bounds(parseFloat(bbox[0]),
+OpenLayers.Bounds.fromArray = function(bbox, reverseAxisOrder) {
+    return reverseAxisOrder === true ?
+           new OpenLayers.Bounds(parseFloat(bbox[1]),
+                                 parseFloat(bbox[0]),
+                                 parseFloat(bbox[3]),
+                                 parseFloat(bbox[2])) :
+           new OpenLayers.Bounds(parseFloat(bbox[0]),
                                  parseFloat(bbox[1]),
                                  parseFloat(bbox[2]),
                                  parseFloat(bbox[3]));

Modified: trunk/openlayers/tests/BaseTypes/Bounds.html
===================================================================
--- trunk/openlayers/tests/BaseTypes/Bounds.html	2011-01-14 16:13:10 UTC (rev 11034)
+++ trunk/openlayers/tests/BaseTypes/Bounds.html	2011-01-17 09:18:21 UTC (rev 11035)
@@ -126,7 +126,7 @@
     }
 
     function test_Bounds_fromString(t) {
-       t.plan( 10 );
+       t.plan( 12 );
        bounds = OpenLayers.Bounds.fromString("1,2,3,4");
        t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
        t.eq( bounds.left, 1, "bounds.left is set correctly" );
@@ -134,13 +134,18 @@
        t.eq( bounds.right, 3, "bounds.right is set correctly" );
        t.eq( bounds.top, 4, "bounds.top is set correctly" );
 
+       // reverse axis order
+       var reverseBbox = bounds.toBBOX(null, true);
+       t.eq(reverseBbox, "2,1,4,3", "toBBOX with reverseAxisOrder set to true works as expected");
+       var boundsFromReverse = OpenLayers.Bounds.fromString(reverseBbox, true);
+       t.ok(bounds.equals(boundsFromReverse), "Bounds created from string with reverseAxisOrder are correct");
+
        bounds = OpenLayers.Bounds.fromString("1.1,2.2,3.3,4.4");
        t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
        t.eq( bounds.left, 1.1, "bounds.left is set correctly" );
        t.eq( bounds.bottom, 2.2, "bounds.bottom is set correctly" );
        t.eq( bounds.right, 3.3, "bounds.right is set correctly" );
        t.eq( bounds.top, 4.4, "bounds.top is set correctly" );
-
     }
 
     function test_Bounds_getSize(t) {
@@ -358,7 +363,7 @@
     }
 
     function test_Bounds_fromArray(t) {
-       t.plan( 5 );
+       t.plan( 7 );
        
        var bbox = [1,2,3,4];
        bounds = OpenLayers.Bounds.fromArray(bbox);
@@ -367,6 +372,12 @@
        t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
        t.eq( bounds.right, 3, "bounds.right is set correctly" );
        t.eq( bounds.top, 4, "bounds.top is set correctly" );
+       
+       // reverse axis order
+       var reverseBbox = bounds.toArray(true);
+       t.eq(reverseBbox, [2,1,4,3], "toArray with reverseAxisOrder set to true works as expected");
+       var boundsFromReverse = OpenLayers.Bounds.fromArray(reverseBbox, true);
+       t.ok(bounds.equals(boundsFromReverse), "Bounds created from array with reverseAxisOrder are correct");
     }
 
     function test_Bounds_fromSize(t) {



More information about the Commits mailing list