1. 倾斜

2. 回正

实现思路
在改变相机视角前,用相机高度和三角函数计算出一个偏移量,改变中心点的经纬度即可
javascript
/**
* 静态工具:根据俯仰角切换相机视角
* @param {Cesium.Viewer} viewer Cesium Viewer
* @param {number} lng 经度
* @param {number} lat 纬度
* @param {number} alt 高度(米)
* @param {number} pitchDeg 俯仰角(角度制,-90 垂直向下)
*/
static updateCameraByPerspective(viewer, lng, lat, alt, pitchDeg) {
if (!viewer || typeof pitchDeg !== 'number') return;
const pitch = Cesium.Math.toRadians(pitchDeg);
let position = Cesium.Cartesian3.fromDegrees(lng, lat, alt);
// 非 90° 俯视时修正位置
const absPitch = Math.abs(pitchDeg);
if (absPitch < 89) {
const offset = alt / Math.tan(absPitch * Math.PI / 180);
const heading = viewer.camera.heading;
const offsetX = -offset * Math.sin(heading);
const offsetY = -offset * Math.cos(heading);
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(position);
const offsetVec = new Cesium.Cartesian3(offsetX, offsetY, 0);
position = Cesium.Matrix4.multiplyByPoint(enu, offsetVec, new Cesium.Cartesian3());
}
viewer.camera.flyTo({
destination: position,
orientation: {
heading: viewer.camera.heading,
pitch,
roll: 0
}
});
}