refactor: 提取地球坐标常量到EARTH_CONFIG
- 添加tilt、chinaLat、chinaLon、latCoefficient等常量 - earth.js和controls.js使用常量替代硬编码 - 离开地球时隐藏tooltip
This commit is contained in:
@@ -9,6 +9,20 @@ export const CONFIG = {
|
|||||||
rotationSpeed: 0.002,
|
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 = {
|
export const PATHS = {
|
||||||
cablesApi: '/api/v1/visualization/geo/cables',
|
cablesApi: '/api/v1/visualization/geo/cables',
|
||||||
landingPointsApi: '/api/v1/visualization/geo/landing-points',
|
landingPointsApi: '/api/v1/visualization/geo/landing-points',
|
||||||
|
|||||||
14
frontend/public/earth/js/controls.js
vendored
14
frontend/public/earth/js/controls.js
vendored
@@ -1,6 +1,6 @@
|
|||||||
// controls.js - Zoom, rotate and toggle controls
|
// 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 { updateZoomDisplay, showStatusMessage } from './ui.js';
|
||||||
import { toggleTerrain } from './earth.js';
|
import { toggleTerrain } from './earth.js';
|
||||||
import { reloadData } from './main.js';
|
import { reloadData } from './main.js';
|
||||||
@@ -153,13 +153,9 @@ function animateValue(start, end, duration, onUpdate, onComplete) {
|
|||||||
export function resetView(camera) {
|
export function resetView(camera) {
|
||||||
if (!earthObj) return;
|
if (!earthObj) return;
|
||||||
|
|
||||||
const chinaLat = 40;
|
const latRot = EARTH_CONFIG.chinaLat * Math.PI / 180;
|
||||||
const chinaLon = -154;
|
const targetRotX = EARTH_CONFIG.tiltRad + latRot * EARTH_CONFIG.latCoefficient;
|
||||||
|
const targetRotY = -(EARTH_CONFIG.chinaRotLon * Math.PI / 180);
|
||||||
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 startRotX = earthObj.rotation.x;
|
const startRotX = earthObj.rotation.x;
|
||||||
const startRotY = earthObj.rotation.y;
|
const startRotY = earthObj.rotation.y;
|
||||||
@@ -176,7 +172,7 @@ export function resetView(camera) {
|
|||||||
updateZoomDisplay(zoomLevel, camera.position.z.toFixed(0));
|
updateZoomDisplay(zoomLevel, camera.position.z.toFixed(0));
|
||||||
}, () => {
|
}, () => {
|
||||||
zoomLevel = 1.0;
|
zoomLevel = 1.0;
|
||||||
showStatusMessage('视角已重置到中国', 'info');
|
showStatusMessage('视角已重置', 'info');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof window.clearLockedCable === 'function') {
|
if (typeof window.clearLockedCable === 'function') {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// earth.js - 3D Earth creation module
|
// earth.js - 3D Earth creation module
|
||||||
|
|
||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
import { CONFIG } from './constants.js';
|
import { CONFIG, EARTH_CONFIG } from './constants.js';
|
||||||
import { latLonToVector3 } from './utils.js';
|
import { latLonToVector3 } from './utils.js';
|
||||||
|
|
||||||
export let earth = null;
|
export let earth = null;
|
||||||
@@ -24,7 +24,7 @@ export function createEarth(scene) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
earth = new THREE.Mesh(geometry, material);
|
earth = new THREE.Mesh(geometry, material);
|
||||||
earth.rotation.x = 23.5 * Math.PI / 180;
|
earth.rotation.x = EARTH_CONFIG.tiltRad;
|
||||||
scene.add(earth);
|
scene.add(earth);
|
||||||
|
|
||||||
const textureUrls = [
|
const textureUrls = [
|
||||||
|
|||||||
Reference in New Issue
Block a user