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:
|
* Parameters:
|
||||||
* ll - {<OpenLayers.LonLat>}
|
* ll - {<OpenLayers.LonLat>}
|
||||||
|
* options - {Object} Optional parameters
|
||||||
|
*
|
||||||
|
* Acceptable options:
|
||||||
* inclusive - {Boolean} Whether or not to include the border.
|
* inclusive - {Boolean} Whether or not to include the border.
|
||||||
* Default is true.
|
* 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:
|
* Returns:
|
||||||
* {Boolean} The passed-in lonlat is within this bounds.
|
* {Boolean} The passed-in lonlat is within this bounds.
|
||||||
*/
|
*/
|
||||||
containsLonLat:function(ll, inclusive) {
|
containsLonLat: function(ll, options) {
|
||||||
return this.contains(ll.lon, ll.lat, inclusive);
|
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;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-12
@@ -1940,18 +1940,8 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
var valid = false;
|
var valid = false;
|
||||||
if (lonlat != null) {
|
if (lonlat != null) {
|
||||||
var maxExtent = this.getMaxExtent();
|
var maxExtent = this.getMaxExtent();
|
||||||
valid = maxExtent.containsLonLat(lonlat);
|
var worldBounds = this.baseLayer.wrapDateLine && maxExtent;
|
||||||
if (!valid && this.baseLayer.wrapDateLine) {
|
valid = maxExtent.containsLonLat(lonlat, {worldBounds: worldBounds});
|
||||||
lonlat = lonlat.clone();
|
|
||||||
var worldWidth = maxExtent.getWidth();
|
|
||||||
while(lonlat.lon > maxExtent.right) {
|
|
||||||
lonlat.lon -= worldWidth;
|
|
||||||
valid = maxExtent.containsLonLat(lonlat);
|
|
||||||
if (valid) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return valid;
|
return valid;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user