Add ol.geom.Polygon#closestPointXY

This commit is contained in:
Tom Payne
2013-12-07 12:44:43 +01:00
parent 0c2a70f3a2
commit cf659f0753

View File

@@ -2,6 +2,7 @@ goog.provide('ol.geom.Polygon');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
goog.require('ol.geom.LinearRing'); goog.require('ol.geom.LinearRing');
goog.require('ol.geom.closest');
goog.require('ol.geom.flat'); goog.require('ol.geom.flat');
goog.require('ol.geom.simplify'); goog.require('ol.geom.simplify');
@@ -35,12 +36,40 @@ ol.geom.Polygon = function(coordinates, opt_layout) {
*/ */
this.interiorPoint_ = null; this.interiorPoint_ = null;
/**
* @private
* @type {number}
*/
this.maxDelta_ = -1;
/**
* @private
* @type {number}
*/
this.maxDeltaRevision_ = -1;
this.setCoordinates(coordinates, opt_layout); this.setCoordinates(coordinates, opt_layout);
}; };
goog.inherits(ol.geom.Polygon, ol.geom.Geometry); goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
/**
* @inheritDoc
*/
ol.geom.Polygon.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) {
if (this.maxDeltaRevision_ != this.revision) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta(
this.flatCoordinates, 0, this.ends_, this.stride, 0));
this.maxDeltaRevision_ = this.revision;
}
return ol.geom.closest.getsClosestPoint(
this.flatCoordinates, 0, this.ends_, this.stride,
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
};
/** /**
* @inheritDoc * @inheritDoc
*/ */