右键不自动回正,改为中键回正(保留动画)

This commit is contained in:
2026-09-19 16:58:36 +08:00
parent 906e53f1d5
commit 174f162565
+14 -9
View File
@@ -228,8 +228,9 @@ export class CesiumGlobe {
},
];
// 阻止右键弹出浏览器菜单
// 阻止右键弹出浏览器菜单;阻止中键触发浏览器自动滚动
scene.canvas.addEventListener('contextmenu', (e) => e.preventDefault());
scene.canvas.addEventListener('mousedown', (e) => { if (e.button === 1) e.preventDefault(); });
// 精细化渲染:高清 + 精细地形
scene.globe.maximumScreenSpaceError = 1.0; // 更精细的地形起伏
@@ -364,16 +365,16 @@ export class CesiumGlobe {
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
}
// 右键原生 tilt 松开后自动回位:按下记录相机状态,松开恢复(并清掉 tilt 惯性余力)
// 右键原生 tilt:按下记录相机状态;松开不回正。中键:回正(flyTo 动画飞回按下前状态)
_setupRightRestore() {
const scene = this.viewer.scene;
const camera = this.viewer.camera;
const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this._rightRestore = null;
this._rightHome = null;
handler.setInputAction(() => {
camera.cancelFlight(); // 取消可能仍在进行的回正动画
this._rightRestore = {
this._rightHome = {
position: Cesium.Cartesian3.clone(camera.position),
direction: Cesium.Cartesian3.clone(camera.direction),
up: Cesium.Cartesian3.clone(camera.up),
@@ -381,18 +382,22 @@ export class CesiumGlobe {
}, Cesium.ScreenSpaceEventType.RIGHT_DOWN);
handler.setInputAction(() => {
if (!this._rightRestore) return;
const s = this._rightRestore;
this._rightRestore = null;
// 松开右键:只清掉 tilt 惯性余力,不回正
const tiltState = scene.screenSpaceCameraController._lastInertiaTiltMovement;
if (tiltState) tiltState.inertiaEnabled = false;
// 回正改用 flyTo 渐变,而不是瞬间 setView
}, Cesium.ScreenSpaceEventType.RIGHT_UP);
handler.setInputAction(() => {
// 中键:回正(动画飞回)
if (!this._rightHome) return;
const s = this._rightHome;
this._rightHome = null;
camera.flyTo({
destination: s.position,
orientation: { direction: s.direction, up: s.up },
duration: 0.5,
});
}, Cesium.ScreenSpaceEventType.RIGHT_UP);
}, Cesium.ScreenSpaceEventType.MIDDLE_DOWN);
this._rightRestoreHandler = handler;
}