From dac7aefeb45235b7954d4a1a0336438d62ed0710 Mon Sep 17 00:00:00 2001 From: fukunee Date: Sat, 19 Sep 2026 02:56:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E8=AE=B0=E4=BE=BF=E7=AD=BE=E5=8F=AF?= =?UTF-8?q?=E8=A7=81=E8=B7=9D=E7=A6=BB=E6=94=B9=E4=B8=BA=208000km?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scene/CesiumGlobe.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/scene/CesiumGlobe.js b/src/scene/CesiumGlobe.js index 763a1cf..97006f6 100644 --- a/src/scene/CesiumGlobe.js +++ b/src/scene/CesiumGlobe.js @@ -1,6 +1,25 @@ -import * as Cesium from 'cesium'; import { ENTRIES } from '../data/entries.js'; +// Cesium 懒加载:脚本首次进入“地理”视图时才加载;用 Proxy 惰性访问 window.Cesium, +// 使下方 50 余处 Cesium.xxx 引用无需逐个改动。 +const Cesium = new Proxy({}, { + get(_t, prop) { return window.Cesium[prop]; }, +}); + +const CESIUM_BASE = '/cesium'; + +function loadCesium() { + return new Promise((resolve, reject) => { + if (window.Cesium) return resolve(); + window.CESIUM_BASE_URL = CESIUM_BASE; + const s = document.createElement('script'); + s.src = `${CESIUM_BASE}/Cesium.js`; + s.onload = () => resolve(); + s.onerror = () => reject(new Error('Cesium 脚本加载失败')); + document.head.appendChild(s); + }); +} + // 免费、无需 Ion 令牌的影像与地形源 const IMAGERY_URL = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'; @@ -107,10 +126,12 @@ export class CesiumGlobe { this.ready = new Promise((resolve) => { this._resolveReady = resolve; }); } - ensureCreated() { + async ensureCreated() { if (this._created) return; this._created = true; + await loadCesium(); + // 调整实体渲染顺序:先渲染标签(城市/国家名),再渲染 Billboard(标记便签), // 让词条标记始终显示在城市/国家名的上层。 Cesium.DataSourceDisplay.defaultVisualizersCallback = function ( @@ -228,6 +249,12 @@ export class CesiumGlobe { viewer.camera.setView({ destination: Cesium.Cartesian3.fromDegrees(35, 12, 7.2e6), }); + + // 创建完成:同步当前选中/可见/相机状态(首次进入时这些调用可能因 viewer 未建而跳过) + this.setSelected(this.selected); + this.setVisible(this._visible); + this.resize(); + this.flyToEntry(this.selected); } _buildMarkers() { @@ -271,7 +298,7 @@ export class CesiumGlobe { _updateMarkerLayer() { const scene = this.viewer.scene; const camera = scene.camera; - const outOfRange = camera.positionCartographic.height > 1e7; // 最远 1 万 km 内显示 + const outOfRange = camera.positionCartographic.height > 8e6; // 最远 8000 km 内显示 for (const m of this.markers) { const el = m.el;