From 82f7aa29a6cb0dc2bbe3bf6fa9779aae2407da0e Mon Sep 17 00:00:00 2001 From: rayd1o Date: Thu, 19 Mar 2026 12:42:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8F=90=E5=8F=96=E5=9C=B0?= =?UTF-8?q?=E7=90=83=E5=9D=90=E6=A0=87=E5=B8=B8=E9=87=8F=E5=88=B0EARTH=5FC?= =?UTF-8?q?ONFIG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加tilt、chinaLat、chinaLon、latCoefficient等常量 - earth.js和controls.js使用常量替代硬编码 - 离开地球时隐藏tooltip --- frontend/public/earth/js/constants.js | 14 ++++++++++++++ frontend/public/earth/js/controls.js | 14 +++++--------- frontend/public/earth/js/earth.js | 6 +++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/frontend/public/earth/js/constants.js b/frontend/public/earth/js/constants.js index 71fce8a3..912783ba 100644 --- a/frontend/public/earth/js/constants.js +++ b/frontend/public/earth/js/constants.js @@ -9,6 +9,20 @@ export const CONFIG = { rotationSpeed: 0.002, }; +// Earth coordinate constants +export const EARTH_CONFIG = { + tilt: 23.5, // earth tilt angle (degrees) + tiltRad: 23.5 * Math.PI / 180, // earth tilt angle (radians) + + // hangzhou coordinates + chinaLat: 30.2741, + chinaLon: 120.1552, + chinaRotLon: 120.1552 - 270, // for rotation calculation (chinaLon - 270) + + // view reset coefficient + latCoefficient: 0.5 +}; + export const PATHS = { cablesApi: '/api/v1/visualization/geo/cables', landingPointsApi: '/api/v1/visualization/geo/landing-points', diff --git a/frontend/public/earth/js/controls.js b/frontend/public/earth/js/controls.js index 1ca92aef..3dfec120 100644 --- a/frontend/public/earth/js/controls.js +++ b/frontend/public/earth/js/controls.js @@ -1,6 +1,6 @@ // controls.js - Zoom, rotate and toggle controls -import { CONFIG } from './constants.js'; +import { CONFIG, EARTH_CONFIG } from './constants.js'; import { updateZoomDisplay, showStatusMessage } from './ui.js'; import { toggleTerrain } from './earth.js'; import { reloadData } from './main.js'; @@ -153,13 +153,9 @@ function animateValue(start, end, duration, onUpdate, onComplete) { export function resetView(camera) { if (!earthObj) return; - const chinaLat = 40; - const chinaLon = -154; - - const baseTilt = 23.5 * Math.PI / 180; - const latRot = chinaLat * Math.PI / 180; - const targetRotX = baseTilt + latRot * 0.5; - const targetRotY = -(chinaLon * Math.PI / 180); + const latRot = EARTH_CONFIG.chinaLat * Math.PI / 180; + const targetRotX = EARTH_CONFIG.tiltRad + latRot * EARTH_CONFIG.latCoefficient; + const targetRotY = -(EARTH_CONFIG.chinaRotLon * Math.PI / 180); const startRotX = earthObj.rotation.x; const startRotY = earthObj.rotation.y; @@ -176,7 +172,7 @@ export function resetView(camera) { updateZoomDisplay(zoomLevel, camera.position.z.toFixed(0)); }, () => { zoomLevel = 1.0; - showStatusMessage('视角已重置到中国', 'info'); + showStatusMessage('视角已重置', 'info'); }); if (typeof window.clearLockedCable === 'function') { diff --git a/frontend/public/earth/js/earth.js b/frontend/public/earth/js/earth.js index 2d16289f..f30934d9 100644 --- a/frontend/public/earth/js/earth.js +++ b/frontend/public/earth/js/earth.js @@ -1,7 +1,7 @@ // earth.js - 3D Earth creation module import * as THREE from 'three'; -import { CONFIG } from './constants.js'; +import { CONFIG, EARTH_CONFIG } from './constants.js'; import { latLonToVector3 } from './utils.js'; export let earth = null; @@ -22,9 +22,9 @@ export function createEarth(scene) { opacity: 0.8, side: THREE.DoubleSide }); - + earth = new THREE.Mesh(geometry, material); - earth.rotation.x = 23.5 * Math.PI / 180; + earth.rotation.x = EARTH_CONFIG.tiltRad; scene.add(earth); const textureUrls = [