Add ol.geom.Polygon#getLinearRing
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user