SOURCE

function lonlatTomercator(lonlat) {
    var mercator={x:0,y:0};
    var x = lonlat.x *20037508.3427892/180;
    var y = Math.log(Math.tan((90+lonlat.y)*Math.PI/360))/(Math.PI/180);
    y = y *20037508.3427892/180;
    mercator.x = x;
    mercator.y = y;
    return mercator ;
}; 

console.log(lonlatTomercator({x:114.616336,y:41.625408
})) 



console.log('----------------------------------') 



function WGS84ToWebMercator(wx,wy){
    var x = wx *20037508.34/180;
    var y = Math.log(Math.tan((90+wy)*Math.PI/360))/(Math.PI/180);
    y = y * 20037508.34/180;
    return {x:x,y:y};
};
console.log(WGS84ToWebMercator(114.616336,41.625408)) 
console 命令行工具 X clear

                    
>
console