cesium 坐标转换

笛卡尔转经纬度

1、 常用 直接装换



let cartographic = Cesium.Cartographic.fromCartesian({x:8283.913,y:7986.217,z:-3.942})
let x = Cesium.Math.toDegrees(cartographic.longitude)
let y = Cesium.Math.toDegrees(cartographic.latitude)
let z =Cesium.Math.toDegrees(cartographic.height)


 
2、通过椭球体转换
 

//需要选着或创建地理坐标的椭球体参数
// 单个坐标
let cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian3);
// 多个坐标
let cartographics = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographic(cartesain3Array);

经纬度转笛卡尔

1、 直接转换


//ellipsoid:该Cartesian3所使用的椭球,默认为Ellipsoid.WGS84  可选
//result:存储结果的对象  可选
Cesium.Cartesian3.fromDegrees(lon,lat, height,ellipsoid, result)

// 批量转  coordinates:[经度,纬度,高度,进度,纬度,高度]
Cesium.Cartesian3.fromDegreesArray(coordinates, ellipsoid, result)

Cesium.Cartesian3.fromDegreesArrayHeights(coordinates);



2、使用椭球体转换

/先转换为弧度坐标
let position = Cesium.Cartographic.fromDegrees(lon, lat, height);
//获取viewer椭球体实例
let ellipsoid = viewer.scene.globe.ellipsoid;
//开始转换
let cartesian3 = ellipsoid.cartographicToCartesian(position);
// 多个坐标
let cartesian3s = ellipsoid.cartographicArrayToCartesianArray(positions);

Cartesian2转Cartesian3

// cartesian2:{x:120,y:100} x是距离屏幕坐标的距离 y是距离屏幕上面的距离

let cartesian3 = viewer.scene.pickPosition(cartesian2);

let cartesain3 = viewer.scene.camera.pickEllipsoid(cartesian2);

let ray = viewer.camera.getPickRay(cartesian2);
let cartesian3 = globe.pick(ray,viewer.scene);

Cartesian3转Cartesian2

Cesium.SceneTransforms.wgs84ToWindowCoordinates(  viewer.scene,{x: -1203323.7985370466, y: 5125803.855493534, z: 3568073.425623818});

你可能感兴趣的:(前端)