/**
* 经纬度坐标转换为3D控件坐标
* lng:纬度
* lat:进度
* radius:半径
*/
js方法转换
function lglt2xyz(lng,lat,radius){
const phi = (180+lng) * (Math.PI/180);
const theta = (90-lat) * (Math.PI/180);
return {
x:-radius * Math.sin(theta) * Math.cos(phi),
y:radius * Math.cos(theta),
z:radius * Math.sin(theta) * Math.sin(phi)
}
}
three.js自带
function lglt2xyz(lng,lat,radius){
const phi = (90-lat) * (Math.PI/180);
const theta = (90+lng) * (Math.PI/180);
return (new THREE.Vector3()).setFromSpherical(new THREE.Spherical(radius,phi,theta));
}
墨卡托投影转换
这个需要引入:d3-array.v1.min.js 和 d3-geo.v1.min.js
const projection = d3.geoMercator().center([104.0, 37.5]).scale(80).translate([0, 0]);