refactor: 提取地球坐标常量到EARTH_CONFIG

- 添加tilt、chinaLat、chinaLon、latCoefficient等常量
- earth.js和controls.js使用常量替代硬编码
- 离开地球时隐藏tooltip
This commit is contained in:
rayd1o
2026-03-19 12:42:08 +08:00
parent 777891f865
commit 82f7aa29a6
3 changed files with 22 additions and 12 deletions

View File

@@ -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',

View File

@@ -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') {

View File

@@ -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;
@@ -24,7 +24,7 @@ export function createEarth(scene) {
});
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 = [