Add ol.geom.LineString#getFlatMidpoint

This commit is contained in:
Tom Payne
2014-01-23 02:03:37 +01:00
parent 155d204938
commit 8e46c91bae
2 changed files with 38 additions and 0 deletions

View File

@@ -20,6 +20,18 @@ ol.geom.LineString = function(coordinates, opt_layout) {
goog.base(this);
/**
* @private
* @type {ol.Coordinate}
*/
this.flatMidpoint_ = null;
/**
* @private
* @type {number}
*/
this.flatMidpointRevision_ = -1;
/**
* @private
* @type {number}
@@ -88,6 +100,20 @@ ol.geom.LineString.prototype.getLength = function() {
};
/**
* @return {Array.<number>} Flat midpoint.
*/
ol.geom.LineString.prototype.getFlatMidpoint = function() {
if (this.flatMidpointRevision_ != this.getRevision()) {
this.flatMidpoint_ = ol.geom.flat.lineStringInterpolate(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
0.5, this.flatMidpoint_);
this.flatMidpointRevision_ = this.getRevision();
}
return this.flatMidpoint_;
};
/**
* @inheritDoc
*/