Files
gods-eye-view/src/layers/submarineCables/bundledSource.js
T
Sameh Khamis f752b5eea1 fix: resolve bundled data URLs when used, not at import
The submarine cable source and the infrastructure data URLs built their
asset URLs from import.meta.url while the module loaded. Importing the
tool services therefore failed in runtimes without a usable module URL,
even for tools that never read those files. Build the URLs when they are
read; Vite still rewrites them in browser builds.
2026-10-03 18:47:31 -07:00

48 lines
1.4 KiB
JavaScript

// This dataset is CC BY-NC-SA 3.0, not the project's MIT license.
// Commercial users must remove it or obtain a TeleGeography license.
// See DATA_SOURCES.md and the bundled dataset's source.json.
// Resolved when read, so importing this module never needs a module URL.
function cableUrl() {
return new URL(
'../../data/local_data/telegeography_submarine_cables/cable-geo.json',
import.meta.url,
).href;
}
function landingPointUrl() {
return new URL(
'../../data/local_data/telegeography_submarine_cables/landing-point-geo.json',
import.meta.url,
).href;
}
/** Supply GeoJSON collections without coupling the renderer to asset URLs. */
export function createBundledCableSource({
fetchImpl = (...args) => fetch(...args),
} = {}) {
async function read(url, signal) {
signal?.throwIfAborted();
const response = await fetchImpl(url, { signal, cache: 'force-cache' });
if (!response.ok) {
try {
await response.body?.cancel();
} catch {
/* best effort */
}
throw new Error(`HTTP ${response.status} for ${url}`);
}
const json = await response.json();
signal?.throwIfAborted();
return json;
}
return {
label: 'TeleGeography',
async fetch(signal) {
const [cables, landingPoints] = await Promise.all([
read(cableUrl(), signal),
read(landingPointUrl(), signal),
]);
return { cables, landingPoints };
},
};
}