mars3d- 坐标的转换

先看看mars3d支持的坐标参数形式:

//1.数组形式
var graphic = new mars3d.graphic.PointEntity({
    position: [116.244399, 30.920459, 573.6],
    style: { color: '#ff0000', pixelSize: 10 },
})

//2.字符串形式
var graphic = new mars3d.graphic.PointEntity({
    position: "116.301798, 30.835848, 915",
    style: { color: '#ff0000', pixelSize: 10 },
})

//3.对象形式
var graphic = new mars3d.graphic.PointEntity({
    position: {lng:116.301798, lat:30.835848, alt:915},
    style: { color: '#ff0000', pixelSize: 10 },
})


//4.Cartesian3对象形式
var graphic = new mars3d.graphic.PointEntity({
    position: Cesium.Cartesian3.fromDegrees(116.308659, 30.914005, 59),
    style: { color: '#ff0000', pixelSize: 10 },
})

//5.LatLngPoint对象形式【建议】
var graphic = new mars3d.graphic.PointEntity({
    position: new mars3d.LngLatPoint(116.301798, 30.835848, 915),
    style: { color: '#ff0000', pixelSize: 10 },
})
 

Cartesian3 格式转换成数组形式

// Cartesian3  格式
const Cartesian3 = {x: -2483911.4536318877, y: 4819824.370398979, z: 3347361.270403664}

// 变成obj形式,也可直接用于矢量数据加载,但是不方便保存数据
console.log(mars3d.LngLatPoint.parse(Cartesian3))
console.log(mars3d.LngLatPoint.fromCartesian(Cartesian3))

// 使用toArray()方法变成数组形式,便于保存数据
console.log(mars3d.LngLatPoint.fromCartesian(graphic.positionShow).toArray())

数组形式 转换成 Cartesian3格式

const positions = [117.205121, 31.866764, 27.4]


// {x: -2478763.515211165, y: 4821722.343135008, z: 3348453.5320802294}

console.log(mars3d.LngLatPoint.toCartesian(positions)) 

console.log(Cesium.Cartesian3.fromDegrees(positions[0], positions[1], positions[2]))

 

你可能感兴趣的:(前端开发,mars3d,坐标,3d)