From 1add41033a71f17f768e6d16adc5e069a50888c7 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 7 Dec 2013 12:43:42 +0100 Subject: [PATCH] Add ol.geom.Point#closestPointXY --- src/ol/geom/point.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ol/geom/point.js b/src/ol/geom/point.js index 13a9973d7f..8d8ab4a343 100644 --- a/src/ol/geom/point.js +++ b/src/ol/geom/point.js @@ -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. */