在线js运行: https://www.bejson.com/runcode/javascript/
// EPSG:3857转换经纬度(EPSG:4326)
console.log("Hello, World");
var center = [13688941.247121427,3221879.4759551883];
function mercatorTolonlat(center){
var lonlat={
x:0,
y:0
};
var x = center[0]/20037508.34*180;
var y = center[1]/20037508.34*180;
y= 180/Math.PI*(2*Math.atan(Math.exp(y*Math.PI/180))-Math.PI/2);
lonlat.x = x;
lonlat.y = y;
return lonlat;
}
console.log(mercatorTolonlat(center));
// 经纬度(EPSG:4326)转换EPSG:3857
// javascript 转换
var lonlat = mercatorTolonlat(center);
function lonLat2Mercator(lonlat){
var mercator = {
x:0,
y:0
};
var earthRad = 6378137.0;
mercator.x = lonlat.lng * Math.PI / 180 * earthRad;
var a = lonlat.lat * Math.PI / 180;
mercator.y = earthRad / 2 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
return mercator;
}
console.log(lonLat2Mercator(lonlat));
参考地址:https://blog.csdn.net/semian7633/article/details/109258717
注意:本文归作者所有,未经作者允许,不得转载