Add ol.geom.LineString#appendCoordinate
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user