Allow access to right-hand oriented polygon coordinates
This commit is contained in:
@@ -151,12 +151,30 @@ ol.geom.Polygon.prototype.getArea = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the coordinate array for this geometry. This array has the structure
|
||||||
|
* of a GeoJSON coordinate array for polygons.
|
||||||
|
*
|
||||||
|
* @param {boolean=} opt_right Orient coordinates according to the right-hand
|
||||||
|
* rule (counter-clockwise for exterior and clockwise for interior rings).
|
||||||
|
* If `false`, coordinates will be oriented according to the left-hand rule
|
||||||
|
* (clockwise for exterior and counter-clockwise for interior rings).
|
||||||
|
* By default, coordinate orientation will depend on how the geometry was
|
||||||
|
* constructed.
|
||||||
* @return {Array.<Array.<ol.Coordinate>>} Coordinates.
|
* @return {Array.<Array.<ol.Coordinate>>} Coordinates.
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.geom.Polygon.prototype.getCoordinates = function() {
|
ol.geom.Polygon.prototype.getCoordinates = function(opt_right) {
|
||||||
|
var flatCoordinates;
|
||||||
|
if (goog.isDef(opt_right)) {
|
||||||
|
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||||
|
ol.geom.flat.orient.orientLinearRings(
|
||||||
|
flatCoordinates, 0, this.ends_, this.stride, opt_right);
|
||||||
|
} else {
|
||||||
|
flatCoordinates = this.flatCoordinates;
|
||||||
|
}
|
||||||
|
|
||||||
return ol.geom.flat.inflate.coordinatess(
|
return ol.geom.flat.inflate.coordinatess(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
flatCoordinates, 0, this.ends_, this.stride);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,30 @@ describe('ol.geom.Polygon', function() {
|
|||||||
expect(polygon.containsCoordinate(insideInner)).to.be(false);
|
expect(polygon.containsCoordinate(insideInner)).to.be(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getCoordinates()', function() {
|
||||||
|
|
||||||
|
var cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
|
||||||
|
var ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
|
||||||
|
var right = new ol.geom.Polygon([ccw, cw]);
|
||||||
|
var left = new ol.geom.Polygon([cw, ccw]);
|
||||||
|
|
||||||
|
it('returns coordinates as they were constructed', function() {
|
||||||
|
expect(right.getCoordinates()).to.eql([ccw, cw]);
|
||||||
|
expect(left.getCoordinates()).to.eql([cw, ccw]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can return coordinates with right-hand orientation', function() {
|
||||||
|
expect(right.getCoordinates(true)).to.eql([ccw, cw]);
|
||||||
|
expect(left.getCoordinates(true)).to.eql([ccw, cw]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can return coordinates with left-hand orientation', function() {
|
||||||
|
expect(right.getCoordinates(false)).to.eql([cw, ccw]);
|
||||||
|
expect(left.getCoordinates(false)).to.eql([cw, ccw]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#getOrientedFlatCoordinates', function() {
|
describe('#getOrientedFlatCoordinates', function() {
|
||||||
|
|
||||||
it('reverses the outer ring if necessary', function() {
|
it('reverses the outer ring if necessary', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user