Add ol.geom.MultiLineString#getFlatMidpoints
This commit is contained in:
@@ -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
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -69,6 +69,14 @@ describe('ol.geom.MultiLineString', function() {
|
|||||||
expect(multiLineString.getStride()).to.be(2);
|
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() {
|
describe('construct with 3D coordinates', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user