Add ol.geom.MultiPolygon#appendPolygon
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
@exportSymbol ol.geom.MultiPolygon
|
||||
@exportProperty ol.geom.MultiPolygon.prototype.appendPolygon
|
||||
@exportProperty ol.geom.MultiPolygon.prototype.clone
|
||||
@exportProperty ol.geom.MultiPolygon.prototype.getArea
|
||||
@exportProperty ol.geom.MultiPolygon.prototype.getCoordinates
|
||||
|
||||
@@ -72,6 +72,31 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) {
|
||||
goog.inherits(ol.geom.MultiPolygon, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Polygon} polygon Polygon.
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.appendPolygon = function(polygon) {
|
||||
goog.asserts.assert(polygon.getLayout() == this.layout);
|
||||
/** @type {Array.<number>} */
|
||||
var ends;
|
||||
if (goog.isNull(this.flatCoordinates)) {
|
||||
this.flatCoordinates = polygon.getFlatCoordinates().slice();
|
||||
ends = polygon.getEnds().slice();
|
||||
this.endss_.push();
|
||||
} else {
|
||||
var offset = this.flatCoordinates.length;
|
||||
goog.array.extend(this.flatCoordinates, polygon.getFlatCoordinates());
|
||||
ends = polygon.getEnds().slice();
|
||||
var i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
ends[i] += offset;
|
||||
}
|
||||
}
|
||||
this.endss_.push(ends);
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,28 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
describe('with an empty MultiPolygon', function() {
|
||||
|
||||
var multiPolygon;
|
||||
beforeEach(function() {
|
||||
multiPolygon = new ol.geom.MultiPolygon(null);
|
||||
});
|
||||
|
||||
it('can append polygons', function() {
|
||||
multiPolygon.appendPolygon(
|
||||
new ol.geom.Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
|
||||
expect(multiPolygon.getCoordinates()).to.eql(
|
||||
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
|
||||
multiPolygon.appendPolygon(
|
||||
new ol.geom.Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
|
||||
expect(multiPolygon.getCoordinates()).to.eql([
|
||||
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
|
||||
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a simple MultiPolygon', function() {
|
||||
|
||||
var multiPolygon;
|
||||
|
||||
Reference in New Issue
Block a user