Add ol.geom.MultiPoint#appendPoint

This commit is contained in:
Tom Payne
2014-03-10 15:45:18 +01:00
parent c2d4ffaba1
commit 033e2e7dd8
3 changed files with 25 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.MultiPoint
@exportProperty ol.geom.MultiPoint.prototype.appendPoint
@exportProperty ol.geom.MultiPoint.prototype.clone
@exportProperty ol.geom.MultiPoint.prototype.getCoordinates
@exportProperty ol.geom.MultiPoint.prototype.getPoints

View File

@@ -1,5 +1,7 @@
goog.provide('ol.geom.MultiPoint');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('ol.extent');
goog.require('ol.geom.GeometryType');
goog.require('ol.geom.Point');
@@ -22,6 +24,20 @@ ol.geom.MultiPoint = function(coordinates, opt_layout) {
goog.inherits(ol.geom.MultiPoint, ol.geom.SimpleGeometry);
/**
* @param {ol.geom.Point} point Point.
*/
ol.geom.MultiPoint.prototype.appendPoint = function(point) {
goog.asserts.assert(point.getLayout() == this.layout);
if (goog.isNull(this.flatCoordinates)) {
this.flatCoordinates = point.getFlatCoordinates().slice();
} else {
goog.array.extend(this.flatCoordinates, point.getFlatCoordinates());
}
this.dispatchChangeEvent();
};
/**
* @inheritDoc
*/

View File

@@ -37,6 +37,13 @@ describe('ol.geom.MultiPoint', function() {
expect(multiPoint.getStride()).to.be(2);
});
it('can append points', function() {
multiPoint.appendPoint(new ol.geom.Point([1, 2]));
expect(multiPoint.getCoordinates()).to.eql([[1, 2]]);
multiPoint.appendPoint(new ol.geom.Point([3, 4]));
expect(multiPoint.getCoordinates()).to.eql([[1, 2], [3, 4]]);
});
});
describe('construct with 2D coordinates', function() {
@@ -170,3 +177,4 @@ describe('ol.geom.MultiPoint', function() {
goog.require('ol.extent');
goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.Point');