From 022ffde95e84eb3f5a0a6b41e51a3b9edacec50d Mon Sep 17 00:00:00 2001 From: euzuro Date: Thu, 25 May 2006 00:54:45 +0000 Subject: [PATCH] moved oppositeQuadrant() function from Anchored.js to Util.js, where it is now a static function on the OpenLayers.Bounds class. Updated usage in code accordingly. Added test. git-svn-id: http://svn.openlayers.org/trunk/openlayers@343 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Popup/Anchored.js | 21 +-------------------- lib/OpenLayers/Util.js | 16 ++++++++++++++++ tests/test_Bounds.html | 11 ++++++++++- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/OpenLayers/Popup/Anchored.js b/lib/OpenLayers/Popup/Anchored.js index 822f8d2d93..304eaec8b0 100644 --- a/lib/OpenLayers/Popup/Anchored.js +++ b/lib/OpenLayers/Popup/Anchored.js @@ -61,7 +61,7 @@ OpenLayers.Popup.Anchored.prototype = var extent = this.map.getExtent(); var quadrant = extent.determineQuadrant(lonlat); - return this.oppositeQuadrant(quadrant); + return OpenLayers.Bounds.oppositeQuadrant(quadrant); }, /** @@ -97,24 +97,5 @@ OpenLayers.Popup.Anchored.prototype = return newPx; }, - /** - * @private - * - * @param {String} quadrant - * - * @returns The opposing quadrant ("br" "tr" "tl" "bl"). For Example, if - * you pass in "bl" it returns "tr", if you pass in "br" it - * returns "tl", etc. - * @type String - */ - oppositeQuadrant: function(quadrant) { - var opp = ""; - - opp += (quadrant.charAt(0) == 't') ? 'b' : 't'; - opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l'; - - return opp; - }, - CLASS_NAME: "OpenLayers.Popup.Anchored" }); diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index a65edbc922..f01d586c78 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -454,6 +454,22 @@ OpenLayers.Bounds.fromString = function(str) { }; +/** + * @param {String} quadrant + * + * @returns The opposing quadrant ("br" "tr" "tl" "bl"). For Example, if + * you pass in "bl" it returns "tr", if you pass in "br" it + * returns "tl", etc. + * @type String + */ +OpenLayers.Bounds.oppositeQuadrant = function(quadrant) { + var opp = ""; + + opp += (quadrant.charAt(0) == 't') ? 'b' : 't'; + opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l'; + + return opp; +}; // Some other helpful things diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index 692835e2c6..adb6613a7f 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -154,7 +154,16 @@ t.eq( bounds.determineQuadrant(bl), "bl", "bounds.determineQuadrant correctly identifies a coordinate in the bottom left quadrant"); t.eq( bounds.determineQuadrant(br), "br", "bounds.determineQuadrant correctly identifies a coordinate in the bottom right quadrant"); } - + + function test_10_Bounds_oppositeQuadrant(t) { + + t.plan( 4 ); + + t.eq( OpenLayers.Bounds.oppositeQuadrant("tl"), "br", "OpenLayers.Bounds.oppositeQuadrant returns 'br' for 'tl'"); + t.eq( OpenLayers.Bounds.oppositeQuadrant("tr"), "bl", "OpenLayers.Bounds.oppositeQuadrant returns 'bl' for 'tr'"); + t.eq( OpenLayers.Bounds.oppositeQuadrant("bl"), "tr", "OpenLayers.Bounds.oppositeQuadrant returns 'tr' for 'bl'"); + t.eq( OpenLayers.Bounds.oppositeQuadrant("br"), "tl", "OpenLayers.Bounds.oppositeQuadrant returns 'tl' for 'br'"); + } // -->