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.
This commit is contained in:
@@ -358,14 +358,43 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
*
|
||||
* Parameters:
|
||||
* ll - {<OpenLayers.LonLat>}
|
||||
* options - {Object} Optional parameters
|
||||
*
|
||||
* Acceptable options:
|
||||
* inclusive - {Boolean} Whether or not to include the border.
|
||||
* Default is true.
|
||||
* worldBounds - {<OpenLayers.Bounds>} 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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user