adding determineQuadrant() function to OpenLayers.Bounds. Tests included.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@334 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -413,6 +413,24 @@ OpenLayers.Bounds.prototype = {
|
|||||||
: (inTop && inLeft && inBottom && inRight);
|
: (inTop && inLeft && inBottom && inRight);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.LonLat} lonlat
|
||||||
|
*
|
||||||
|
* @returns The quadrant ("br" "tr" "tl" "bl") of the bounds in which
|
||||||
|
* the coordinate lies.
|
||||||
|
* @type String
|
||||||
|
*/
|
||||||
|
determineQuadrant: function(lonlat) {
|
||||||
|
|
||||||
|
var quadrant = "";
|
||||||
|
var center = this.getCenterLonLat();
|
||||||
|
|
||||||
|
quadrant += (lonlat.lat < center.lat) ? "b" : "t";
|
||||||
|
quadrant += (lonlat.lon < center.lon) ? "l" : "r";
|
||||||
|
|
||||||
|
return quadrant;
|
||||||
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
CLASS_NAME: "OpenLayers.Bounds"
|
CLASS_NAME: "OpenLayers.Bounds"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -139,6 +139,21 @@
|
|||||||
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_09_Bounds_determineQuadrant(t) {
|
||||||
|
|
||||||
|
t.plan( 4 );
|
||||||
|
var bounds = new OpenLayers.Bounds(0,0,100,100);
|
||||||
|
|
||||||
|
var tl = new OpenLayers.LonLat(25, 75);
|
||||||
|
var tr = new OpenLayers.LonLat(75, 75);
|
||||||
|
var bl = new OpenLayers.LonLat(25, 25);
|
||||||
|
var br = new OpenLayers.LonLat(75, 25);
|
||||||
|
|
||||||
|
t.eq( bounds.determineQuadrant(tl), "tl", "bounds.determineQuadrant correctly identifies a coordinate in the top left quadrant");
|
||||||
|
t.eq( bounds.determineQuadrant(tr), "tr", "bounds.determineQuadrant correctly identifies a coordinate in the top right quadrant");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
// -->
|
// -->
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user