Make ol.geom.Circle support #intersectsExtent, with tests

This commit is contained in:
Alvin Lindstam
2015-06-05 10:47:54 +02:00
parent 405d5666e2
commit 1dc6c99328
2 changed files with 47 additions and 0 deletions

View File

@@ -137,6 +137,29 @@ ol.geom.Circle.prototype.getType = function() {
};
/**
* @inheritDoc
* @api stable
*/
ol.geom.Circle.prototype.intersectsExtent = function(extent) {
var circleExtent = this.getExtent();
if (ol.extent.intersects(extent, circleExtent)) {
var center = this.getCenter();
if (extent[0] <= center[0] && extent[2] >= center[0]) {
return true;
}
if (extent[1] <= center[1] && extent[3] >= center[1]) {
return true;
}
return ol.extent.forEachCorner(extent, this.containsCoordinate, this);
}
return false;
};
/**
* Set the center of the circle as {@link ol.Coordinate coordinate}.
* @param {ol.Coordinate} center Center.