geoCentroid function Spherical math
Returns the spherical centroid of the specified GeoJSON object
.
This is the spherical equivalent of GeoPath.centroid.
Implementation
List<double> geoCentroid(Map object) {
_w0 = _w1 = _x0 = _y0 = _z0 = _x1 = _y1 = _z1 = 0;
_x2 = Adder();
_y2 = Adder();
_z2 = Adder();
_centroidStream(object);
var x = _x2.valueOf(),
y = _y2.valueOf(),
z = _z2.valueOf(),
m = hypot([x, y, z]);
// If the area-weighted ccentroid is undefined,
// fall back to length-weighted ccentroid.
if (m < epsilon2) {
x = _x1;
y = _y1;
z = _z1;
// If the feature has zero length,
// fall back to arithmetic mean of point vectors.
if (_w1 < epsilon) {
x = _x0;
y = _y0;
z = _z0;
}
m = hypot([x, y, z]);
// If the feature still has an undefined ccentroid, then return.
if (m < epsilon2) return [double.nan, double.nan];
}
return [atan2(y, x) * degrees, asin(z / m) * degrees];
}