Giving fromArray and fromString a reverseAxisOrder option. r=erilem (closes #3014)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11035 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -615,14 +615,15 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
*
|
||||
* 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 @@ OpenLayers.Bounds.fromString = function(str) {
|
||||
*
|
||||
* 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]));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user