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,9 +153,10 @@ function animateValue(start, end, duration, onUpdate, onComplete) {
export function resetView(camera) {
if (!earthObj) return;
const latRot = EARTH_CONFIG.chinaLat * Math.PI / 180;
function animateToView(targetLat, targetLon, targetRotLon) {
const latRot = targetLat * Math.PI / 180;
const targetRotX = EARTH_CONFIG.tiltRad + latRot * EARTH_CONFIG.latCoefficient;
const targetRotY = -(EARTH_CONFIG.chinaRotLon * Math.PI / 180);
const targetRotY = -(targetRotLon * Math.PI / 180);
const startRotX = earthObj.rotation.x;
const startRotY = earthObj.rotation.y;
@@ -174,6 +175,17 @@ export function resetView(camera) {
zoomLevel = 1.0;
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') {
window.clearLockedCable();