diff --git a/src/ol/geom/geometry.exports b/src/ol/geom/geometry.exports index f53f11edbc..9737cb2f7d 100644 --- a/src/ol/geom/geometry.exports +++ b/src/ol/geom/geometry.exports @@ -1,4 +1,5 @@ @exportSymbol ol.geom.Geometry +@exportProperty ol.geom.Geometry.prototype.getClosestPoint @exportProperty ol.geom.Geometry.prototype.getExtent @exportProperty ol.geom.Geometry.prototype.getLayout @exportProperty ol.geom.Geometry.prototype.getSimplifiedGeometry diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index 7f85cdafcb..d6ea82e51c 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -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