Move ol.Sphere#circle to ol.geom.Polygon.circular

Previously, ol.geom.Polygon was a transitive dependency of ol.proj (since ol.proj requires ol.sphere.NORMAL, and all spheres were capable of generating circular polygons).  Instead, ol.proj should be lower-level.  Since it deals only with coordinate arrays, it shouldn't depend on all of the geometry code.

By adding a static `circular` function to `ol.geom.Polygon`, the dependency tree makes more sense.  If you want to create a polygon that approximates a circle on a sphere, you require `ol.geom.Polygon` and `ol.Sphere` (or one of the constants).

This makes room for geometries to have a `transform` method that takes projection-like arguments (meaning that `ol.geom.Geometry` will require `ol.proj`).
This commit is contained in:
Tim Schaub
2014-05-02 11:25:44 -06:00
parent 015aab8af3
commit 1110da37e1
4 changed files with 32 additions and 31 deletions

View File

@@ -12,7 +12,6 @@ goog.provide('ol.Sphere');
goog.require('goog.array');
goog.require('goog.math');
goog.require('ol.geom.Polygon');
@@ -30,33 +29,6 @@ ol.Sphere = function(radius) {
};
/**
* Returns an approximation to a circle centered on `center` with radius
* `radius` with `n` distinct points.
*
* @param {ol.Coordinate} center Center.
* @param {number} radius Radius.
* @param {number=} opt_n N.
* @return {ol.geom.Geometry} Circle geometry.
* @todo api
*/
ol.Sphere.prototype.circle = function(center, radius, opt_n) {
var n = goog.isDef(opt_n) ? opt_n : 32;
/** @type {Array.<number>} */
var flatCoordinates = [];
var i;
for (i = 0; i < n; ++i) {
goog.array.extend(
flatCoordinates, this.offset(center, radius, 2 * Math.PI * i / n));
}
flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);
var polygon = new ol.geom.Polygon(null);
polygon.setFlatCoordinates(
ol.geom.GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
return polygon;
};
/**
* Returns the distance from c1 to c2 using the spherical law of cosines.
*