固定坐标系
var currentHeading = viewer.camera.heading;
var currentPitch = viewer.camera.pitch;
var currentRoll = viewer.camera.roll;
var currentPosition = viewer.camera.position;
// 在ENU坐标系中创建一个指向北的单位向量
var northVectorENU = new window.Cesium.Cartesian3(0.0, 1.0, 0.0); // 向北移动
var southVectorENU = new window.Cesium.Cartesian3(0.0, -1.0, 0.0); // 向南移动
var eastVectorENU = new window.Cesium.Cartesian3(1.0, 0.0, 0.0); // 向东移动
var westVectorENU = new window.Cesium.Cartesian3(-1.0, 0.0, 0.0); // 向西移动
// 创建变换矩阵,用于从ENU坐标系到固定参考坐标系的转换
var enuToFixedMatrix = window.Cesium.Transforms.eastNorthUpToFixedFrame(currentPosition, viewer.scene.globe.ellipsoid);
let northVectorFixed: any
// 使用变换矩阵将向量从ENU坐标系转换到固定参考坐标系
switch (num) {
case 1:
northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, northVectorENU, new window.Cesium.Cartesian3()); // 向北移动
break;
case 2:
northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, southVectorENU, new window.Cesium.Cartesian3()); // 向南移动
break;
case 3:
northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, eastVectorENU, new window.Cesium.Cartesian3()); // 向东移动
break;
case 4:
northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, westVectorENU, new window.Cesium.Cartesian3()); // 向西移动
break;
}
// 将向量缩放到所需的距离
northVectorFixed = window.Cesium.Cartesian3.multiplyByScalar(northVectorFixed, 1000, northVectorFixed);
// 创建新位置
var newPosition = window.Cesium.Cartesian3.add(currentPosition, northVectorFixed, new window.Cesium.Cartesian3());
// 设置新的相机视图
viewer.camera.setView({
destination: newPosition,
orientation: {
heading: currentHeading,
pitch: currentPitch,
roll: currentRoll
}
});
经纬度
var currentHeading = viewer.camera.heading;
var currentPitch = viewer.camera.pitch;
var currentRoll = viewer.camera.roll;
var currentPosition = viewer.camera.position;
// 创建一个Cartesian3 clone of the current position
var newPosition = window.Cesium.Cartesian3.clone(currentPosition);
// 将位置转换为地理坐标
var ellipsoid = viewer.scene.globe.ellipsoid;
var cartographic = ellipsoid.cartesianToCartographic(newPosition);
// 向北
cartographic.latitude += window.Cesium.Math.toRadians(1); // 向北 1 向南 -1
// 增加经度(向东移动)
// cartographic.longitude += window.Cesium.Math.toRadians(1); // 向东 1 向西 -1
// 将新的地理坐标转换回Cartesian3
newPosition = ellipsoid.cartographicToCartesian(cartographic);
// 设置新的相机视图
viewer.camera.setView({
destination: newPosition,
heading: currentHeading,
pitch: currentPitch,
roll: currentRoll
});