Add loading overlay while scenes initialize
- Show a spinner overlay that fades out once Cesium globe data is ready, with a 1s minimum and 8s timeout - Expose a ready promise on CesiumGlobe resolved after country and city data load - Remove temporary inspect script
This commit is contained in:
+13
@@ -8,3 +8,16 @@ for (const ev of ['copy', 'cut', 'contextmenu']) {
|
||||
// 启动应用
|
||||
const app = new App();
|
||||
window.__app = app; // 便于调试
|
||||
|
||||
// 加载界面:等三个视图初始化完成(最少展示 1 秒,最多等 8 秒)后淡出
|
||||
const t0 = Date.now();
|
||||
const MIN_DISPLAY = 1000;
|
||||
Promise.race([
|
||||
app.globe.ready,
|
||||
new Promise((r) => setTimeout(r, 8000)),
|
||||
]).then(() => {
|
||||
const wait = Math.max(0, MIN_DISPLAY - (Date.now() - t0));
|
||||
setTimeout(() => {
|
||||
document.getElementById('loading').classList.add('hidden');
|
||||
}, wait);
|
||||
});
|
||||
|
||||
@@ -69,6 +69,8 @@ export class CesiumGlobe {
|
||||
this.selected = -1;
|
||||
this._created = false;
|
||||
this._visible = false;
|
||||
this._pendingData = 2; // 国家边界 + 城市数据
|
||||
this.ready = new Promise((resolve) => { this._resolveReady = resolve; });
|
||||
}
|
||||
|
||||
ensureCreated() {
|
||||
@@ -316,6 +318,8 @@ export class CesiumGlobe {
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[CesiumGlobe] 行政区划加载失败:', err);
|
||||
} finally {
|
||||
this._dataReady();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,6 +366,15 @@ export class CesiumGlobe {
|
||||
},
|
||||
});
|
||||
}
|
||||
this._dataReady();
|
||||
}
|
||||
|
||||
_dataReady() {
|
||||
this._pendingData--;
|
||||
if (this._pendingData <= 0 && this._resolveReady) {
|
||||
this._resolveReady();
|
||||
this._resolveReady = null;
|
||||
}
|
||||
}
|
||||
|
||||
setSelected(index) {
|
||||
|
||||
@@ -52,6 +52,29 @@ html, body {
|
||||
background: #0c0906; opacity: 0; transition: opacity 0.18s ease;
|
||||
}
|
||||
|
||||
/* 加载界面 */
|
||||
#loading {
|
||||
position: fixed; inset: 0; z-index: 1000;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
background: #14100d;
|
||||
transition: opacity 0.6s ease;
|
||||
}
|
||||
#loading.hidden { opacity: 0; pointer-events: none; }
|
||||
.loading-box { display: flex; flex-direction: column; align-items: center; gap: 18px; }
|
||||
.spinner {
|
||||
width: 54px; height: 54px;
|
||||
border: 3px solid rgba(201, 162, 39, 0.22);
|
||||
border-top-color: #c9a227;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
.loading-text {
|
||||
font-family: var(--serif);
|
||||
font-size: 14px; letter-spacing: 0.3em;
|
||||
color: rgba(230, 216, 182, 0.7);
|
||||
}
|
||||
|
||||
/* 顶部标题 */
|
||||
.hud { position: absolute; z-index: 5; }
|
||||
.top-left { top: 22px; left: 26px; }
|
||||
|
||||
Reference in New Issue
Block a user