Add ol.geom.Polygon#getLinearRing

This commit is contained in:
Tom Payne
2014-03-10 15:40:05 +01:00
parent 03911e6c6b
commit c2d4ffaba1
3 changed files with 22 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
@exportProperty ol.geom.Polygon.prototype.getArea
@exportProperty ol.geom.Polygon.prototype.getCoordinates
@exportProperty ol.geom.Polygon.prototype.getInteriorPoint
@exportProperty ol.geom.Polygon.prototype.getLinearRing
@exportProperty ol.geom.Polygon.prototype.getLinearRings
@exportProperty ol.geom.Polygon.prototype.getType
@exportProperty ol.geom.Polygon.prototype.setCoordinates

View File

@@ -178,6 +178,22 @@ ol.geom.Polygon.prototype.getInteriorPoint = function() {
};
/**
* @param {number} index Index.
* @return {ol.geom.LinearRing} Linear ring.
*/
ol.geom.Polygon.prototype.getLinearRing = function(index) {
goog.asserts.assert(0 <= index && index < this.ends_.length);
if (index < 0 || this.ends_.length <= index) {
return null;
}
var linearRing = new ol.geom.LinearRing(null);
linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
return linearRing;
};
/**
* @return {Array.<ol.geom.LinearRing>} Linear rings.
* @todo stability experimental

View File

@@ -84,6 +84,11 @@ describe('ol.geom.Polygon', function() {
expect(polygon.getStride()).to.be(2);
});
it('can return individual rings', function() {
expect(polygon.getLinearRing(0).getCoordinates()).to.eql(outerRing);
expect(polygon.getLinearRing(1).getCoordinates()).to.eql(innerRing);
});
it('has the expected rings', function() {
var linearRings = polygon.getLinearRings();
expect(linearRings).to.be.an(Array);