Add ol.geom.MultiLineString#getFlatMidpoints

This commit is contained in:
Tom Payne
2014-01-23 02:05:36 +01:00
parent 8e46c91bae
commit a37199675c
2 changed files with 29 additions and 0 deletions

View File

@@ -112,6 +112,27 @@ ol.geom.MultiLineString.prototype.getLineStrings = function() {
};
/**
* @return {Array.<number>} Flat midpoints.
*/
ol.geom.MultiLineString.prototype.getFlatMidpoints = function() {
var midpoints = [];
var flatCoordinates = this.flatCoordinates;
var offset = 0;
var ends = this.ends_;
var stride = this.stride;
var i, ii;
for (i = 0, ii = ends.length; i < ii; ++i) {
var end = ends[i];
var midpoint = ol.geom.flat.lineStringInterpolate(
flatCoordinates, offset, end, stride, 0.5);
goog.array.extend(midpoints, midpoint);
offset = end;
}
return midpoints;
};
/**
* @inheritDoc
*/

View File

@@ -69,6 +69,14 @@ describe('ol.geom.MultiLineString', function() {
expect(multiLineString.getStride()).to.be(2);
});
describe('#getFlatMidpoints', function() {
it('returns the expected result', function() {
expect(multiLineString.getFlatMidpoints()).to.eql([2, 3, 6, 7]);
});
});
});
describe('construct with 3D coordinates', function() {