add containsPixel() and containsLonLat() functions to OpenLayers.Bounds object. added tests
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1506 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -424,6 +424,30 @@ OpenLayers.Bounds.prototype = {
|
|||||||
this.right + x, this.top + y);
|
this.right + x, this.top + y);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.LonLat} ll
|
||||||
|
* @param {Boolean} inclusive Whether or not to include the border.
|
||||||
|
* Default is true
|
||||||
|
*
|
||||||
|
* @return Whether or not the passed-in lonlat is within this bounds
|
||||||
|
* @type Boolean
|
||||||
|
*/
|
||||||
|
containsLonLat:function(ll, inclusive) {
|
||||||
|
return this.contains(ll.lon, ll.lat, inclusive);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.Pixel} px
|
||||||
|
* @param {Boolean} inclusive Whether or not to include the border.
|
||||||
|
* Default is true
|
||||||
|
*
|
||||||
|
* @return Whether or not the passed-in pixel is within this bounds
|
||||||
|
* @type Boolean
|
||||||
|
*/
|
||||||
|
containsPixel:function(px, inclusive) {
|
||||||
|
return this.contains(px.x, px.y, inclusive);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {float} x
|
* @param {float} x
|
||||||
* @param {float} y
|
* @param {float} y
|
||||||
|
|||||||
@@ -53,12 +53,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_04_Bounds_contains(t) {
|
function test_04_Bounds_contains(t) {
|
||||||
t.plan( 4 );
|
t.plan( 6 );
|
||||||
bounds = new OpenLayers.Bounds(10,10,40,40);
|
bounds = new OpenLayers.Bounds(10,10,40,40);
|
||||||
t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" );
|
t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" );
|
||||||
t.eq( bounds.contains(0,0), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" );
|
t.eq( bounds.contains(0,0), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" );
|
||||||
t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" );
|
t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" );
|
||||||
t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" );
|
t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" );
|
||||||
|
|
||||||
|
var px = new OpenLayers.Pixel(15,30);
|
||||||
|
t.eq( bounds.containsPixel(px), bounds.contains(px.x, px.y), "containsPixel works");
|
||||||
|
|
||||||
|
var ll = new OpenLayers.LonLat(15,30);
|
||||||
|
t.eq( bounds.containsLonLat(ll), bounds.contains(ll.lon, ll.lat), "containsLonLat works");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_05_Bounds_fromString(t) {
|
function test_05_Bounds_fromString(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user