资源本地化
This commit is contained in:
@@ -153,6 +153,24 @@
|
||||
let myMap2D = null;
|
||||
let editingRouteId = null;
|
||||
|
||||
async function fetchJsonWithFallback(urls) {
|
||||
let lastError = null;
|
||||
|
||||
for (const url of urls) {
|
||||
try {
|
||||
const response = await fetch(url, { cache: 'force-cache' });
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
lastError = err;
|
||||
}
|
||||
}
|
||||
|
||||
throw lastError || new Error('All JSON sources failed');
|
||||
}
|
||||
|
||||
// ---- Initialize ----
|
||||
function init() {
|
||||
// Resource Gauges Time
|
||||
@@ -752,9 +770,10 @@
|
||||
}
|
||||
|
||||
try {
|
||||
// Fetch map data
|
||||
const resp = await fetch('https://cdn.jsdelivr.net/npm/echarts@4.9.0/map/json/world.json');
|
||||
const worldJSON = await resp.json();
|
||||
// Fetch map data with CDN fallback so restricted networks degrade more gracefully.
|
||||
const worldJSON = await fetchJsonWithFallback([
|
||||
'/vendor/world.json'
|
||||
]);
|
||||
|
||||
// Transform to Pacific-centered correctly
|
||||
const transformCoords = (coords) => {
|
||||
@@ -865,6 +884,8 @@
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Map2D] Initialization failed:', err);
|
||||
dom.globeContainer.innerHTML = '<div class="chart-empty">Map data unavailable</div>';
|
||||
myMap2D = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user