标记便签可见距离改为 8000km
This commit is contained in:
@@ -1,6 +1,25 @@
|
|||||||
import * as Cesium from 'cesium';
|
|
||||||
import { ENTRIES } from '../data/entries.js';
|
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 令牌的影像与地形源
|
// 免费、无需 Ion 令牌的影像与地形源
|
||||||
const IMAGERY_URL =
|
const IMAGERY_URL =
|
||||||
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
|
'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; });
|
this.ready = new Promise((resolve) => { this._resolveReady = resolve; });
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureCreated() {
|
async ensureCreated() {
|
||||||
if (this._created) return;
|
if (this._created) return;
|
||||||
this._created = true;
|
this._created = true;
|
||||||
|
|
||||||
|
await loadCesium();
|
||||||
|
|
||||||
// 调整实体渲染顺序:先渲染标签(城市/国家名),再渲染 Billboard(标记便签),
|
// 调整实体渲染顺序:先渲染标签(城市/国家名),再渲染 Billboard(标记便签),
|
||||||
// 让词条标记始终显示在城市/国家名的上层。
|
// 让词条标记始终显示在城市/国家名的上层。
|
||||||
Cesium.DataSourceDisplay.defaultVisualizersCallback = function (
|
Cesium.DataSourceDisplay.defaultVisualizersCallback = function (
|
||||||
@@ -228,6 +249,12 @@ export class CesiumGlobe {
|
|||||||
viewer.camera.setView({
|
viewer.camera.setView({
|
||||||
destination: Cesium.Cartesian3.fromDegrees(35, 12, 7.2e6),
|
destination: Cesium.Cartesian3.fromDegrees(35, 12, 7.2e6),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 创建完成:同步当前选中/可见/相机状态(首次进入时这些调用可能因 viewer 未建而跳过)
|
||||||
|
this.setSelected(this.selected);
|
||||||
|
this.setVisible(this._visible);
|
||||||
|
this.resize();
|
||||||
|
this.flyToEntry(this.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildMarkers() {
|
_buildMarkers() {
|
||||||
@@ -271,7 +298,7 @@ export class CesiumGlobe {
|
|||||||
_updateMarkerLayer() {
|
_updateMarkerLayer() {
|
||||||
const scene = this.viewer.scene;
|
const scene = this.viewer.scene;
|
||||||
const camera = scene.camera;
|
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) {
|
for (const m of this.markers) {
|
||||||
const el = m.el;
|
const el = m.el;
|
||||||
|
|||||||
Reference in New Issue
Block a user