From 99042c956af66a529e152bd577fa17da9a022107 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 7 Dec 2013 12:45:02 +0100 Subject: [PATCH] Add ol.geom.MultiPoint#closestPointXY --- src/ol/geom/multipoint.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ol/geom/multipoint.js b/src/ol/geom/multipoint.js index 3092b41284..0330e274d1 100644 --- a/src/ol/geom/multipoint.js +++ b/src/ol/geom/multipoint.js @@ -19,6 +19,27 @@ ol.geom.MultiPoint = function(coordinates, opt_layout) { goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry); +/** + * @inheritDoc + */ +ol.geom.MultiPoint.prototype.closestPointXY = + function(x, y, closestPoint, minSquaredDistance) { + var flatCoordinates = this.flatCoordinates; + var stride = this.stride; + var i, ii; + for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) { + var squaredDistance = ol.geom.flat.squaredDistance( + x, y, flatCoordinates[i], flatCoordinates[i + 1]); + if (squaredDistance < minSquaredDistance) { + minSquaredDistance = squaredDistance; + closestPoint[0] = flatCoordinates[i]; + closestPoint[1] = flatCoordinates[i + 1]; + } + } + return minSquaredDistance; +}; + + /** * @return {ol.geom.RawMultiPoint} Coordinates. */