diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 6602d76439..5220788901 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -424,6 +424,30 @@ OpenLayers.Bounds.prototype = { 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} y diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index 2a0561c9fe..2f9aaa6235 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -53,12 +53,19 @@ } function test_04_Bounds_contains(t) { - t.plan( 4 ); + t.plan( 6 ); 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(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, 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) {