@jindin/js-coordinate-transformer
Version:
百度地图(BD09)、高德地图(火星坐标GCJ02)和WGS84坐标系相互转换
59 lines (58 loc) • 2.36 kB
JavaScript
const g = 52.35987755982988, c = 3.141592653589793, l = 6378245, u = 0.006693421622965943, m = (n, t) => n < 72.004 || n > 137.8347 || t < 0.8293 || t > 55.8271 || !1;
function d(n, t) {
let s = -100 + 2 * n + 3 * t + 0.2 * t * t + 0.1 * n * t + 0.2 * Math.sqrt(Math.abs(n));
return s += (20 * Math.sin(6 * n * c) + 20 * Math.sin(2 * n * c)) * 2 / 3, s += (20 * Math.sin(t * c) + 40 * Math.sin(t / 3 * c)) * 2 / 3, s += (160 * Math.sin(t / 12 * c) + 320 * Math.sin(t * c / 30)) * 2 / 3, s;
}
function f(n, t) {
let s = 300 + n + 2 * t + 0.1 * n * n + 0.1 * n * t + 0.1 * Math.sqrt(Math.abs(n));
return s += (20 * Math.sin(6 * n * c) + 20 * Math.sin(2 * n * c)) * 2 / 3, s += (20 * Math.sin(n * c) + 40 * Math.sin(n / 3 * c)) * 2 / 3, s += (150 * Math.sin(n / 12 * c) + 300 * Math.sin(n / 30 * c)) * 2 / 3, s;
}
const q = (n) => {
const [t, s] = n, a = 3.141592653589793 * 3e3 / 180, e = t - 65e-4, r = s - 6e-3, o = Math.sqrt(e * e + r * r) - 2e-5 * Math.sin(r * a), h = Math.atan2(r, e) - 3e-6 * Math.cos(e * a), M = o * Math.cos(h), i = o * Math.sin(h);
return [M, i];
}, G = (n) => {
const [t, s] = n, a = Math.sqrt(t * t + s * s) + 2e-5 * Math.sin(s * g), e = Math.atan2(s, t) + 3e-6 * Math.cos(t * g), r = a * Math.cos(e) + 65e-4, o = a * Math.sin(e) + 6e-3;
return [r, o];
}, _ = (n) => {
const [t, s] = n;
if (m(t, s))
return [t, s];
{
let a = d(t - 105, s - 35), e = f(t - 105, s - 35);
const r = s / 180 * c;
let o = Math.sin(r);
o = 1 - u * o * o;
const h = Math.sqrt(o);
a = a * 180 / (l * (1 - u) / (o * h) * c), e = e * 180 / (l / h * Math.cos(r) * c);
const M = s + a;
return [t + e, M];
}
}, b = (n) => {
const [t, s] = n;
if (m(t, s))
return [t, s];
{
let a = d(t - 105, s - 35), e = f(t - 105, s - 35);
const r = s / 180 * c;
let o = Math.sin(r);
o = 1 - u * o * o;
const h = Math.sqrt(o);
a = a * 180 / (l * (1 - u) / (o * h) * c), e = e * 180 / (l / h * Math.cos(r) * c);
const M = s + a, i = t + e;
return [t * 2 - i, s * 2 - M];
}
}, C = (n) => {
const [t, s] = n, a = q([t, s]);
return b([a[0], a[1]]);
}, x = (n) => {
const [t, s] = n, a = _([t, s]);
return G([a[0], a[1]]);
};
export {
q as calBD09toGCJ02,
C as calBD09toWGS84,
G as calGCJ02toBD09,
b as calGCJ02toWGS84,
x as calWGS84toBD09,
_ as calWGS84toGCJ02
};