feat(earth): request geolocation on resetView, fallback to China

This commit is contained in:
rayd1o
2026-03-19 12:49:38 +08:00
parent 1189fec014
commit 6fabbcfe5c

View File

@@ -153,27 +153,39 @@ function animateValue(start, end, duration, onUpdate, onComplete) {
export function resetView(camera) { export function resetView(camera) {
if (!earthObj) return; if (!earthObj) return;
const latRot = EARTH_CONFIG.chinaLat * Math.PI / 180; function animateToView(targetLat, targetLon, targetRotLon) {
const targetRotX = EARTH_CONFIG.tiltRad + latRot * EARTH_CONFIG.latCoefficient; const latRot = targetLat * Math.PI / 180;
const targetRotY = -(EARTH_CONFIG.chinaRotLon * Math.PI / 180); const targetRotX = EARTH_CONFIG.tiltRad + latRot * EARTH_CONFIG.latCoefficient;
const targetRotY = -(targetRotLon * Math.PI / 180);
const startRotX = earthObj.rotation.x; const startRotX = earthObj.rotation.x;
const startRotY = earthObj.rotation.y; const startRotY = earthObj.rotation.y;
const startZoom = zoomLevel; const startZoom = zoomLevel;
const targetZoom = 1.0; const targetZoom = 1.0;
animateValue(0, 1, 800, (progress) => { animateValue(0, 1, 800, (progress) => {
const ease = 1 - Math.pow(1 - progress, 3); const ease = 1 - Math.pow(1 - progress, 3);
earthObj.rotation.x = startRotX + (targetRotX - startRotX) * ease; earthObj.rotation.x = startRotX + (targetRotX - startRotX) * ease;
earthObj.rotation.y = startRotY + (targetRotY - startRotY) * ease; earthObj.rotation.y = startRotY + (targetRotY - startRotY) * ease;
zoomLevel = startZoom + (targetZoom - startZoom) * ease; zoomLevel = startZoom + (targetZoom - startZoom) * ease;
camera.position.z = CONFIG.defaultCameraZ / zoomLevel; camera.position.z = CONFIG.defaultCameraZ / zoomLevel;
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 (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(pos) => animateToView(pos.coords.latitude, pos.coords.longitude, -pos.coords.longitude),
() => animateToView(EARTH_CONFIG.chinaLat, EARTH_CONFIG.chinaLon, EARTH_CONFIG.chinaRotLon),
{ timeout: 5000, enableHighAccuracy: false }
);
} else {
animateToView(EARTH_CONFIG.chinaLat, EARTH_CONFIG.chinaLon, EARTH_CONFIG.chinaRotLon);
}
if (typeof window.clearLockedCable === 'function') { if (typeof window.clearLockedCable === 'function') {
window.clearLockedCable(); window.clearLockedCable();