右键 tilt 松开后自动归位(记录/恢复相机状态)

This commit is contained in:
2026-09-19 14:36:37 +08:00
parent 0dd279f2b5
commit 1126f9a79e
+29 -1
View File
@@ -255,6 +255,7 @@ export class CesiumGlobe {
this._buildMarkers();
this._setupPick();
this._setupRightRestore();
this._loadBoundaries();
this._buildCityLabels();
@@ -355,7 +356,34 @@ export class CesiumGlobe {
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
}
// 右键环视:地表附近右键拖动,以点击点为球心调整视角,松开归位
// 右键操作(原生 tilt)松开后自动归位:记录按下前状态,松开时恢复
_setupRightRestore() {
const scene = this.viewer.scene;
const camera = this.viewer.camera;
const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this._rightRestore = null;
handler.setInputAction(() => {
this._rightRestore = {
position: Cesium.Cartesian3.clone(camera.position),
direction: Cesium.Cartesian3.clone(camera.direction),
up: Cesium.Cartesian3.clone(camera.up),
};
}, Cesium.ScreenSpaceEventType.RIGHT_DOWN);
handler.setInputAction(() => {
if (!this._rightRestore) return;
const s = this._rightRestore;
this._rightRestore = null;
camera.setView({
destination: s.position,
orientation: { direction: s.direction, up: s.up },
});
}, Cesium.ScreenSpaceEventType.RIGHT_UP);
this._rightRestoreHandler = handler;
}
// 相机平滑飞至某个标记上空并居中:回到与初始一致的高度与北朝上方向,左键拖拽手感不变
flyToEntry(index) {
const entry = ENTRIES[index];