From 77a658ddee5fdf5dcfedbea825a478ae748944eb Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 7 Dec 2013 12:45:45 +0100 Subject: [PATCH] Add ol.geom.MultiPolygon#closestPointXY --- src/ol/geom/multipolygon.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index 657a461b12..b9aca5c04b 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -2,6 +2,7 @@ goog.provide('ol.geom.MultiPolygon'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.Polygon'); +goog.require('ol.geom.closest'); goog.require('ol.geom.flat'); goog.require('ol.geom.simplify'); @@ -35,12 +36,40 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) { */ this.interiorPoints_ = null; + /** + * @private + * @type {number} + */ + this.maxDelta_ = -1; + + /** + * @private + * @type {number} + */ + this.maxDeltaRevision_ = -1; + this.setCoordinates(coordinates, opt_layout); }; goog.inherits(ol.geom.MultiPolygon, ol.geom.Geometry); +/** + * @inheritDoc + */ +ol.geom.MultiPolygon.prototype.closestPointXY = + function(x, y, closestPoint, minSquaredDistance) { + if (this.maxDeltaRevision_ != this.revision) { + this.maxDelta_ = Math.sqrt(ol.geom.closest.getssMaxSquaredDelta( + this.flatCoordinates, 0, this.endss_, this.stride, 0)); + this.maxDeltaRevision_ = this.revision; + } + return ol.geom.closest.getssClosestPoint( + this.flatCoordinates, 0, this.endss_, this.stride, + this.maxDelta_, true, x, y, closestPoint, minSquaredDistance); +}; + + /** * @inheritDoc */