Add ol.geom.LineString#closestPointXY

This commit is contained in:
Tom Payne
2013-12-07 12:44:00 +01:00
parent 1add41033a
commit a19daf4b1d

View File

@@ -1,6 +1,7 @@
goog.provide('ol.geom.LineString');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.closest');
goog.require('ol.geom.flat');
goog.require('ol.geom.simplify');
@@ -13,12 +14,43 @@ goog.require('ol.geom.simplify');
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
ol.geom.LineString = function(coordinates, opt_layout) {
goog.base(this);
/**
* @private
* @type {number}
*/
this.maxDelta_ = -1;
/**
* @private
* @type {number}
*/
this.maxDeltaRevision_ = -1;
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
/**
* @inheritDoc
*/
ol.geom.LineString.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) {
if (this.maxDeltaRevision_ != this.revision) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
this.maxDeltaRevision_ = this.revision;
}
return ol.geom.closest.getClosestPoint(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
};
/**
* @return {ol.geom.RawLineString} Coordinates.
*/