Published
Edited
Feb 18, 2019
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function stabWernerRaw(ratio, max) {
/*
* simplified Bonne, with phi0 = halfPi ;
* https://github.com/d3/d3-geo-projection/blob/master/src/bonne.js
*/
function r(lambda, phi) {
const rho = halfPi - phi,
e = rho ? (lambda * cos(phi)) / rho : rho;
return [rho * sin(e), -rho * cos(e)];
}
r.invert = function(x, y) {
var rho = sqrt(x ** 2 + y ** 2),
phi = halfPi - rho;
return [(rho / cos(phi)) * atan2(x, -y), phi];
};

/* azimuthal equidistant for the pole part */
const az = d3
.geoAzimuthalEquidistant()
.rotate([0, -90])
.translate([0, 0])
.scale(1);

/* mix */
function forward(lambda, phi) {
if (phi < max * radians) {
lambda *= ratio;
return r(lambda, phi);
} else {
const p = az([lambda * degrees, phi * degrees]);
return [p[0], -p[1]];
}
}

function invert(x, y) {
let i = az.invert([x, -y]);
if (i[1] < max) {
i = r.invert(x, y);
i[0] /= ratio;
} else {
i[0] *= radians;
i[1] *= radians;
}
return [i[0], i[1]];
}

forward.invert = invert;

return forward;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more