Lazily create and toggle Cesium globe visibility

The globe container now uses a `visible` class instead of
`display`, allowing the Cesium viewer to be pre-created on page
load while remaining hidden until the geographic view is selected.
This commit is contained in:
2026-09-19 01:12:45 +08:00
parent 71750e5dad
commit 58bc998c6e
3 changed files with 30 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
import puppeteer from 'puppeteer-core';
const CHROME = 'C:/Program Files/Google/Chrome/Application/chrome.exe';
const browser = await puppeteer.launch({ executablePath: CHROME, headless: 'new',
args: ['--no-sandbox', '--disable-gpu', '--use-gl=swiftshader', '--enable-unsafe-swiftshader', '--window-size=1440,900'] });
const page = await browser.newPage();
await page.setViewport({ width: 1440, height: 900 });
const errors = [];
page.on('pageerror', (e) => errors.push(e.message));
page.on('console', (m) => { if (m.type() === 'error') errors.push('console: ' + m.text()); });
await page.goto('http://localhost:5250/', { waitUntil: 'domcontentloaded', timeout: 60000 });
await new Promise(r => setTimeout(r, 8000));
// 还没切到地理视图,Cesium 应该已经创建
const pre = await page.evaluate(() => {
const g = window.__app.globe;
return { created: !!(g && g.viewer), markers: g && g.markers ? g.markers.length : 0 };
});
console.log('启动即创建:', JSON.stringify(pre));
await page.click('.view-btn[data-view="globe"]');
await new Promise(r => setTimeout(r, 2000));
const after = await page.evaluate(() => {
const el = document.getElementById('cesium-container');
return { visible: el.classList.contains('visible'), visibility: getComputedStyle(el).visibility };
});
console.log('切到地理:', JSON.stringify(after));
console.log('ERRORS', errors.length ? errors.join(' | ') : '(none)');
await browser.close();