From 174f1625655c53e27edd9078e2b4c165c0cf0b7b Mon Sep 17 00:00:00 2001 From: fukunee Date: Sat, 19 Sep 2026 16:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B3=E9=94=AE=E4=B8=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=9B=9E=E6=AD=A3=EF=BC=8C=E6=94=B9=E4=B8=BA=E4=B8=AD=E9=94=AE?= =?UTF-8?q?=E5=9B=9E=E6=AD=A3=EF=BC=88=E4=BF=9D=E7=95=99=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scene/CesiumGlobe.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/scene/CesiumGlobe.js b/src/scene/CesiumGlobe.js index c04a9a6..599149f 100644 --- a/src/scene/CesiumGlobe.js +++ b/src/scene/CesiumGlobe.js @@ -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; }