diff --git a/src/ol/geom/linestring.exports b/src/ol/geom/linestring.exports index f5c50bdf5c..f1f95ce7c1 100644 --- a/src/ol/geom/linestring.exports +++ b/src/ol/geom/linestring.exports @@ -1,4 +1,5 @@ @exportSymbol ol.geom.LineString +@exportProperty ol.geom.LineString.prototype.appendCoordinate @exportProperty ol.geom.LineString.prototype.clone @exportProperty ol.geom.LineString.prototype.getCoordinateAtM @exportProperty ol.geom.LineString.prototype.getCoordinates diff --git a/src/ol/geom/linestring.js b/src/ol/geom/linestring.js index 989c9c88bb..8ac6ec912e 100644 --- a/src/ol/geom/linestring.js +++ b/src/ol/geom/linestring.js @@ -1,5 +1,7 @@ goog.provide('ol.geom.LineString'); +goog.require('goog.array'); +goog.require('goog.asserts'); goog.require('ol.extent'); goog.require('ol.geom.GeometryType'); goog.require('ol.geom.SimpleGeometry'); @@ -50,6 +52,20 @@ ol.geom.LineString = function(coordinates, opt_layout) { goog.inherits(ol.geom.LineString, ol.geom.SimpleGeometry); +/** + * @param {ol.Coordinate} coordinate Coordinate. + */ +ol.geom.LineString.prototype.appendCoordinate = function(coordinate) { + goog.asserts.assert(coordinate.length == this.stride); + if (goog.isNull(this.flatCoordinates)) { + this.flatCoordinates = coordinate.slice(); + } else { + goog.array.extend(this.flatCoordinates, coordinate); + } + this.dispatchChangeEvent(); +}; + + /** * @inheritDoc */ diff --git a/test/spec/ol/geom/linestring.test.js b/test/spec/ol/geom/linestring.test.js index a09ee352be..f4546bc59e 100644 --- a/test/spec/ol/geom/linestring.test.js +++ b/test/spec/ol/geom/linestring.test.js @@ -37,6 +37,13 @@ describe('ol.geom.LineString', function() { expect(lineString.getStride()).to.be(2); }); + it('can append coordinates', function() { + lineString.appendCoordinate([1, 2]); + expect(lineString.getCoordinates()).to.eql([[1, 2]]); + lineString.appendCoordinate([3, 4]); + expect(lineString.getCoordinates()).to.eql([[1, 2], [3, 4]]); + }); + }); describe('construct with 2D coordinates', function() {