Add ol.geom.MultiLineString#getLineString
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
@exportProperty ol.geom.MultiLineString.prototype.clone
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getCoordinateAtM
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getCoordinates
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getLineString
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getLineStrings
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getType
|
||||
@exportProperty ol.geom.MultiLineString.prototype.setCoordinates
|
||||
|
||||
@@ -131,6 +131,22 @@ ol.geom.MultiLineString.prototype.getEnds = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} index Index.
|
||||
* @return {ol.geom.LineString} LineString.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getLineString = function(index) {
|
||||
goog.asserts.assert(0 <= index && index < this.ends_.length);
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
var lineString = new ol.geom.LineString(null);
|
||||
lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
|
||||
return lineString;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.geom.LineString>} LineStrings.
|
||||
* @todo stability experimental
|
||||
|
||||
@@ -142,6 +142,17 @@ describe('ol.geom.MultiLineString', function() {
|
||||
expect(multiLineString.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
it('can return individual line strings', function() {
|
||||
var lineString0 = multiLineString.getLineString(0);
|
||||
expect(lineString0).to.be.an(ol.geom.LineString);
|
||||
expect(lineString0.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(lineString0.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
|
||||
var lineString1 = multiLineString.getLineString(1);
|
||||
expect(lineString1).to.be.an(ol.geom.LineString);
|
||||
expect(lineString1.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(lineString1.getCoordinates()).to.eql([[7, 8, 9], [10, 11, 12]]);
|
||||
});
|
||||
|
||||
describe('#getCoordinateAtM', function() {
|
||||
|
||||
describe('with extrapolation and interpolation', function() {
|
||||
|
||||
Reference in New Issue
Block a user