Add ol.geom.Polygon#appendLinearRing
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.Polygon
|
@exportSymbol ol.geom.Polygon
|
||||||
|
@exportProperty ol.geom.Polygon.prototype.appendLinearRing
|
||||||
@exportProperty ol.geom.Polygon.prototype.clone
|
@exportProperty ol.geom.Polygon.prototype.clone
|
||||||
@exportProperty ol.geom.Polygon.prototype.getArea
|
@exportProperty ol.geom.Polygon.prototype.getArea
|
||||||
@exportProperty ol.geom.Polygon.prototype.getCoordinates
|
@exportProperty ol.geom.Polygon.prototype.getCoordinates
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
goog.provide('ol.geom.Polygon');
|
goog.provide('ol.geom.Polygon');
|
||||||
|
|
||||||
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.GeometryType');
|
goog.require('ol.geom.GeometryType');
|
||||||
@@ -71,6 +72,21 @@ ol.geom.Polygon = function(coordinates, opt_layout) {
|
|||||||
goog.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);
|
goog.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.LinearRing} linearRing Linear ring.
|
||||||
|
*/
|
||||||
|
ol.geom.Polygon.prototype.appendLinearRing = function(linearRing) {
|
||||||
|
goog.asserts.assert(linearRing.getLayout() == this.layout);
|
||||||
|
if (goog.isNull(this.flatCoordinates)) {
|
||||||
|
this.flatCoordinates = linearRing.getFlatCoordinates().slice();
|
||||||
|
} else {
|
||||||
|
goog.array.extend(this.flatCoordinates, linearRing.getFlatCoordinates());
|
||||||
|
}
|
||||||
|
this.ends_.push(this.flatCoordinates.length);
|
||||||
|
this.dispatchChangeEvent();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -37,6 +37,17 @@ describe('ol.geom.Polygon', function() {
|
|||||||
expect(polygon.getStride()).to.be(2);
|
expect(polygon.getStride()).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can append linear rings', function() {
|
||||||
|
polygon.appendLinearRing(
|
||||||
|
new ol.geom.LinearRing([[1, 2], [3, 4], [5, 6]]));
|
||||||
|
expect(polygon.getCoordinates()).to.eql(
|
||||||
|
[[[1, 2], [3, 4], [5, 6]]]);
|
||||||
|
polygon.appendLinearRing(
|
||||||
|
new ol.geom.LinearRing([[7, 8], [9, 10], [11, 12]]));
|
||||||
|
expect(polygon.getCoordinates()).to.eql(
|
||||||
|
[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('construct with 2D coordinates', function() {
|
describe('construct with 2D coordinates', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user