Add ol.geom.Geometry#getClosestPoint

This commit is contained in:
Tom Payne
2013-12-07 12:43:22 +01:00
parent 74bf8a7ecb
commit 35c20bea79
2 changed files with 25 additions and 0 deletions

View File

@@ -103,6 +103,30 @@ ol.geom.Geometry = function() {
goog.inherits(ol.geom.Geometry, ol.Observable);
/**
* @param {number} x X.
* @param {number} y Y.
* @param {ol.Coordinate} closestPoint Closest point.
* @param {number} minSquaredDistance Minimum squared distance.
* @return {number} Minimum squared distance.
*/
ol.geom.Geometry.prototype.closestPointXY = goog.abstractMethod;
/**
* @param {ol.Coordinate} point Point.
* @param {ol.Coordinate=} opt_closestPoint Closest point.
* @return {ol.Coordinate} Closest point.
*/
ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
// FIXME check extent
var closestPoint = goog.isDef(opt_closestPoint) ?
opt_closestPoint : [NaN, NaN];
this.closestPointXY(point[0], point[1], closestPoint, Infinity);
return closestPoint;
};
/**
* @param {number} stride Stride.
* @private