Add ol.geom.Point#closestPointXY

This commit is contained in:
Tom Payne
2013-12-07 12:43:42 +01:00
parent 35c20bea79
commit 1add41033a

View File

@@ -20,6 +20,24 @@ ol.geom.Point = function(coordinates, opt_layout) {
goog.inherits(ol.geom.Point, ol.geom.Geometry);
/**
* @inheritDoc
*/
ol.geom.Point.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) {
var flatCoordinates = this.flatCoordinates;
var squaredDistance = ol.geom.flat.squaredDistance(
x, y, flatCoordinates[0], flatCoordinates[1]);
if (squaredDistance < minSquaredDistance) {
closestPoint[0] = flatCoordinates[0];
closestPoint[1] = flatCoordinates[1];
return squaredDistance;
} else {
return minSquaredDistance;
}
};
/**
* @return {ol.geom.RawPoint} Coordinates.
*/