From 0277eb1ed3fd5ad6f952a7e74c52a3951eee97b8 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 29 Sep 2011 13:38:40 -0600 Subject: [PATCH] worldBounds option for containsLonLat. This is basically the same enhancement we made for intersectsBounds, and we no longer have to do dateline shifting in other components to get proper containsLonLat results. --- lib/OpenLayers/BaseTypes/Bounds.js | 33 ++++++++++++++++++++++++++++-- lib/OpenLayers/Map.js | 14 ++----------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index 6c85c8ab0b..83e0c79ded 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -358,14 +358,43 @@ OpenLayers.Bounds = OpenLayers.Class({ * * Parameters: * ll - {} + * options - {Object} Optional parameters + * + * Acceptable options: * inclusive - {Boolean} Whether or not to include the border. * Default is true. + * worldBounds - {} If a worldBounds is provided, the + * ll will be considered as contained if it exceeds the world bounds, + * but can be wrapped around the dateline so it is contained by this + * bounds. * * Returns: * {Boolean} The passed-in lonlat is within this bounds. */ - containsLonLat:function(ll, inclusive) { - return this.contains(ll.lon, ll.lat, inclusive); + containsLonLat: function(ll, options) { + options = options || {}; + if (typeof options === "boolean") { + options.inclusive = options; + } + var contains = this.contains(ll.lon, ll.lat, options.inclusive), + worldBounds = options.worldBounds; + if (worldBounds && !contains) { + var worldWidth = worldBounds.getWidth(); + ll = ll.clone(); + while(!contains && ll.lon > worldBounds.right) { + ll.lon -= worldWidth; + contains = worldBounds.containsLonLat( + ll, {inclusive: options.inclusive} + ); + } + while(!contains && ll.lon < worldBounds.left) { + ll.lon += worldWidth; + contains = worldBounds.containsLonLat( + ll, {inclusive: options.inclusive} + ); + } + } + return contains; }, /** diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 78eb0c3f74..44771f09ce 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1940,18 +1940,8 @@ OpenLayers.Map = OpenLayers.Class({ var valid = false; if (lonlat != null) { var maxExtent = this.getMaxExtent(); - valid = maxExtent.containsLonLat(lonlat); - if (!valid && this.baseLayer.wrapDateLine) { - lonlat = lonlat.clone(); - var worldWidth = maxExtent.getWidth(); - while(lonlat.lon > maxExtent.right) { - lonlat.lon -= worldWidth; - valid = maxExtent.containsLonLat(lonlat); - if (valid) { - break; - } - } - } + var worldBounds = this.baseLayer.wrapDateLine && maxExtent; + valid = maxExtent.containsLonLat(lonlat, {worldBounds: worldBounds}); } return valid; },