javascript的84与墨卡托投影坐标转换

​
//84坐标转墨卡托投影坐标
function wgs84mercatorto(L,B,degree){
    var xy=[0,0];
    var a = 6378137.0;
    var b = 6356752.314245179;
    var e = 0.081819190842621;
    var eC = 0.0820944379496957;
    var L0 = 0.0;

    var n;
    if (degree == 6.0) {
        n = Math.round((L + degree / 2.0) / degree);
        L0 = degree * n - degree / 2.0;
    } else {
        n = Math.round(L / degree);
        L0 = degree * n;
    }

    var radB = B * 3.141592653589793/180;
    var radL = L * 3.141592653589793/180;
    var deltaL = (L - L0) * 3.141592653589793/180;
    var N = a * a / b / Math.sqrt(1 + eC * eC * Math.cos(radB) * Math.cos(radB));
    var C1 = 1.0 + 0.75 * e * e + 0.703125 * Math.pow(e, 4.0) + 0.68359375 * Math.pow(e, 6.0) + 0.67291259765625 * Math.pow(e, 8.0);
    var C2 = 0.75 * e * e + 0.9375 * Math.pow(e, 4.0) + 1.025390625 * Math.pow(e, 6.0) + 1.07666015625 * Math.pow(e, 8.0);
    var C3 = 0.234375 * Math.pow(e, 4.0) + 0.41015625 * Math.pow(e, 6.0) + 0.538330078125 * Math.pow(e, 8.0);
    var C4 = 0.068359375 * Math.pow(e, 6.0) + 0.15380859375 * Math.pow(e, 8.0);
    var C5 = 0.00240325927734375 * Math.pow(e, 8.0);
    var t = Math.tan(radB);
    var eta = eC * Math.cos(radB);
    var X = a * (1 - e * e) * (C1 * radB - C2 * Math.sin(2 * radB) / 2 + C3 * Math.sin(4 * radB) / 4 - C4 * Math.sin(6 * radB) / 6 + C5 * Math.sin(8 * radB));
    xy[0] = X + N * Math.sin(radB) * Math.cos(radB) * Math.pow(deltaL, 2.0) * (1 + Math.pow(deltaL * Math.cos(radB), 2.0) * (5 - t * t + 9 * eta * eta + 4 * Math.pow(eta, 4.0)) / 12 + Math.pow(deltaL * Math.cos(radB), 4.0) * (61 - 58 * t * t + Math.pow(t, 4.0)) / 360) / 2;
    xy[1] = N * deltaL * Math.cos(radB) * (1 + Math.pow(deltaL * Math.cos(radB), 2.0) * (1 - t * t + eta * eta) / 6 + Math.pow(deltaL * Math.cos(radB), 4.0) * (5 - 18 * t * t + Math.pow(t, 4.0) - 14 * eta * eta - 58 * eta * eta * t * t) / 120) + 500000;

    return xy;

}

//墨卡托投影转84坐标
function mercator2towgs84(X,Y,L0){
    var p = 206264.80624709636;

    var lat ,lon;
    Y-=500000;
    var   result  = [];
    var iPI = 0.0174532925199433;//pi/180
    var a = 6378137.0; //长半轴 m
    var b = 6356752.31414; //短半轴 m
    var f = 1/298.257222101;//扁率 a-b/a
    var e1 = 0.0818191910428; //第一偏心率 Math.sqrt(5)
    var ee = Math.sqrt(a*a-b*b)/b; //第二偏心率
    var bf = 0; //底点纬度
    var a0 = 1+(3*e1*e1/4) + (45*e1*e1*e1*e1/64) + (175*e1*e1*e1*e1*e1*e1/256) + (11025*e1*e1*e1*e1*e1*e1*e1*e1/16384) + (43659*e1*e1*e1*e1*e1*e1*e1*e1*e1*e1/65536);
    var b0 = X/(a*(1-e1*e1)*a0);
    var c1 = 3*e1*e1/8 +3*e1*e1*e1*e1/16 + 213*e1*e1*e1*e1*e1*e1/2048 + 255*e1*e1*e1*e1*e1*e1*e1*e1/4096;
    var c2 = 21*e1*e1*e1*e1/256 + 21*e1*e1*e1*e1*e1*e1/256 + 533*e1*e1*e1*e1*e1*e1*e1*e1/8192;
    var c3 = 151*e1*e1*e1*e1*e1*e1*e1*e1/6144 + 151*e1*e1*e1*e1*e1*e1*e1*e1/4096;
    var c4 = 1097*e1*e1*e1*e1*e1*e1*e1*e1/131072;
    bf = b0 + c1*Math.sin(2*b0) + c2*Math.sin(4*b0) +c3*Math.sin(6*b0) + c4*Math.sin(8*b0); // bf =b0+c1*sin2b0 + c2*sin4b0 + c3*sin6b0 +c4*sin8b0 +...
    var tf = Math.tan(bf);
    var n2 = ee*ee*Math.cos(bf)*Math.cos(bf); //第二偏心率平方成bf余弦平方
    var c = a*a/b;
    var v=Math.sqrt(1+ ee*ee*Math.cos(bf)*Math.cos(bf));
    var mf = c/(v*v*v); //子午圈半径
    var nf = c/v;//卯酉圈半径

    //纬度计算
    lat=bf-(tf/(2*mf)*Y)*(Y/nf) * (1-1/12*(5+3*tf*tf+n2-9*n2*tf*tf)*(Y*Y/(nf*nf))+1/360*(61+90*tf*tf+45*tf*tf*tf*tf)*(Y*Y*Y*Y/(nf*nf*nf*nf)));
    //经度偏差
    lon=1/(nf*Math.cos(bf))*Y -(1/(6*nf*nf*nf*Math.cos(bf)))*(1+2*tf*tf +n2)*Y*Y*Y + (1/(120*nf*nf*nf*nf*nf*Math.cos(bf)))*(5+28*tf*tf+24*tf*tf*tf*tf)*Y*Y*Y*Y*Y;
    result[0] =lat/iPI;
    result[1] =L0+lon/iPI;
    return result;
}

​

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪豹_黑狐

谢谢大家的支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值