cesium中常用的坐标有两种WGS84地理坐标系和笛卡尔空间坐标系(世界坐标)。我们平时常用的以经纬度来指明一个地点就是用的WGS84坐标,笛卡尔空间坐标系常用来做一些空间位置变换如平移旋转缩放等等。二者的联系如下图, 笛卡尔空间坐标的原点就是椭球的中心.
Pick----屏幕坐标 Cartesian----世界坐标 cartographic-----地理坐标(弧度) Point----经纬度坐标
1.屏幕坐标转世界坐标
var pick= new Cesium.Cartesian2(window.innerWidth,window.innerHeight);
var cartesian = scene.globe.pick(viewer.camera.getPickRay(pick), scene);
注:一共是两步
(在2D下上述方法不适用,改成:
var pick= new Cesium.Cartesian2(0,0); var cartesian = viewer.camera.pickEllipsoid(pick, viewer.scene.globe.ellipsoid); )
2.世界坐标转地理坐标(弧度)
var cartographic = scene.globe.ellipsoid.cartesianToCartographic(cartesian);
或
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
3.世界坐标转屏幕坐标
var pick = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, cartesian);
4.地理坐标(弧度)转经纬度坐标
var point=[ cartographic.longitude / Math.PI * 180, cartographic.latitude / Math.PI * 180];
5.地理坐标(弧度)转世界坐标
var cartesian = scene.globe.ellipsoid. cartographicTo Cartesian (cartographic);
6.经纬度坐标转地理坐标(弧度)
var cartographic = Cesium.Cartographic.fromDegree(point);
7.经纬度坐标转世界坐标
var cartesian = Cesium. Cartesian 3.fromDegree(point);