Add ol.geom.MultiLineString#appendLineString

This commit is contained in:
Tom Payne
2014-03-10 16:18:12 +01:00
parent 7ee4fb8a2e
commit 7a51b4c7b6
3 changed files with 28 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.MultiLineString
@exportProperty ol.geom.MultiLineString.prototype.appendLineString
@exportProperty ol.geom.MultiLineString.prototype.clone
@exportProperty ol.geom.MultiLineString.prototype.getCoordinateAtM
@exportProperty ol.geom.MultiLineString.prototype.getCoordinates

View File

@@ -47,6 +47,22 @@ ol.geom.MultiLineString = function(coordinates, opt_layout) {
goog.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry);
/**
* @param {ol.geom.LineString} lineString LineString.
*/
ol.geom.MultiLineString.prototype.appendLineString = function(lineString) {
goog.asserts.assert(lineString.getLayout() == this.layout);
if (goog.isNull(this.flatCoordinates)) {
this.flatCoordinates = lineString.getFlatCoordinates().slice();
} else {
goog.array.extend(
this.flatCoordinates, lineString.getFlatCoordinates().slice());
}
this.ends_.push(this.flatCoordinates.length);
this.dispatchChangeEvent();
};
/**
* @inheritDoc
*/

View File

@@ -37,6 +37,17 @@ describe('ol.geom.MultiLineString', function() {
expect(multiLineString.getStride()).to.be(2);
});
it('can append line strings', function() {
multiLineString.appendLineString(
new ol.geom.LineString([[1, 2], [3, 4]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]]]);
multiLineString.appendLineString(
new ol.geom.LineString([[5, 6], [7, 8]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
});
});
describe('construct with 2D coordinates', function() {