UNPKG

jr-util

Version:

这是MJR的JS工具库。定期更新

2 lines (1 loc) 2.15 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var o=3.141592653589793,v=o*3e3/180,u=6378245,d=.006693421622965943;function g(a,t){if(m(a,t))return{lat:a,lon:t};var n=j(t-105,a-35),r=l(t-105,a-35),e=a/180*o,s=Math.sin(e);s=1-d*s*s;var c=Math.sqrt(s);n=n*180/(u*(1-d)/(s*c)*o),r=r*180/(u/c*Math.cos(e)*o);var M=a+n,i=t+r;return{lat:M,lon:i}}function f(a,t){var n=t,r=a,e=Math.sqrt(n*n+r*r)+2e-5*Math.sin(r*v),s=Math.atan2(r,n)+3e-6*Math.cos(n*v),c=e*Math.cos(s)+.0065,M=e*Math.sin(s)+.006;return{lat:M,lon:c}}function q(a,t){var n=g(a,t),r=f(n.lat,n.lon);return r}function T(a,t){if(m(a,t))return{lat:a,lon:t};var n=j(t-105,a-35),r=l(t-105,a-35),e=a/180*o,s=Math.sin(e);s=1-d*s*s;var c=Math.sqrt(s);n=n*180/(u*(1-d)/(s*c)*o),r=r*180/(u/c*Math.cos(e)*o);var M=a+n,i=t+r;return{lat:a*2-M,lon:t*2-i}}function L(a,t){var n=t-.0065,r=a-.006,e=Math.sqrt(n*n+r*r)-2e-5*Math.sin(r*v),s=Math.atan2(r,n)-3e-6*Math.cos(n*v),c=e*Math.cos(s),M=e*Math.sin(s);return{lat:M,lon:c}}function b(a,t){var n=L(a,t),r=T(n.lat,n.lon);return r}function j(a,t){var n=-100+2*a+3*t+.2*t*t+.1*a*t+.2*Math.sqrt(Math.abs(a));return n+=(20*Math.sin(6*a*o)+20*Math.sin(2*a*o))*2/3,n+=(20*Math.sin(t*o)+40*Math.sin(t/3*o))*2/3,n+=(160*Math.sin(t/12*o)+320*Math.sin(t*o/30))*2/3,n}function l(a,t){var n=300+a+2*t+.1*a*a+.1*a*t+.1*Math.sqrt(Math.abs(a));return n+=(20*Math.sin(6*a*o)+20*Math.sin(2*a*o))*2/3,n+=(20*Math.sin(a*o)+40*Math.sin(a/3*o))*2/3,n+=(150*Math.sin(a/12*o)+300*Math.sin(a/30*o))*2/3,n}function m(a,t){return t<72.004||t>137.8347||a<.8293||a>55.8271}const _=(a,t,n)=>{let r=[];for(let e=0;e<a;e++){let s=Math.random()*(t.lat-n.lat)+n.lat,c=Math.random()*(n.lon-t.lon)+t.lon;r.push({lon:c,lat:s})}return r},h=a=>a*Math.PI/180,P=(a,t,n,r)=>{const s=h(n-a),c=h(r-t),M=Math.sin(s/2)*Math.sin(s/2)+Math.cos(h(a))*Math.cos(h(n))*Math.sin(c/2)*Math.sin(c/2),i=2*Math.atan2(Math.sqrt(M),Math.sqrt(1-M));return 6371e3*i};exports.bd09ToGcj02=L;exports.bd09ToWgs84=b;exports.calcDistance=P;exports.gcj02ToBd09=f;exports.gcj02ToWgs84=T;exports.generateRandomPoints=_;exports.wgs84ToBd09=q;exports.wgs84ToGcj02=g;