feat: v0.4.1 — untrack map-asset pack (~100 MB): compose volume mount + runtime fallback to remote OFM styles
This commit is contained in:
@@ -38,6 +38,33 @@ export function styleUrl(id: string): string {
|
||||
return `/styles/${id}.json`;
|
||||
}
|
||||
|
||||
// Remote fallback base for styles when the local asset pack is absent (fresh clone
|
||||
// without `npm run assets:download` / no volume mount). The raw OFM styles already
|
||||
// point glyphs/sprites at remote URLs, so they work as-is — only vector tiles were
|
||||
// ever remote. A future self-hosted tile pack plugs into the same availability
|
||||
// mechanism below (the manifest describes the whole local asset set).
|
||||
export const REMOTE_STYLE_BASE = 'https://tiles.openfreemap.org/styles';
|
||||
|
||||
export function styleUrlFor(id: string, localAssetsAvailable: boolean): string {
|
||||
return localAssetsAvailable ? `/styles/${id}.json` : `${REMOTE_STYLE_BASE}/${id}`;
|
||||
}
|
||||
|
||||
// The manifest is written LAST by scripts/download-map-assets.mjs, so its presence
|
||||
// means the whole pack (styles + fonts + sprites — and any future asset class) is in
|
||||
// place. Probed once per page life via a module-level cached promise: any non-200 or
|
||||
// network error → false (fall back to remote styles).
|
||||
const MANIFEST_URL = '/map-assets-manifest.json';
|
||||
let assetsProbePromise: Promise<boolean> | null = null;
|
||||
|
||||
export function localAssetsAvailable(): Promise<boolean> {
|
||||
if (!assetsProbePromise) {
|
||||
assetsProbePromise = fetch(MANIFEST_URL, { cache: 'no-store' })
|
||||
.then((res) => res.ok)
|
||||
.catch(() => false);
|
||||
}
|
||||
return assetsProbePromise;
|
||||
}
|
||||
|
||||
type Source = Record<string, unknown>;
|
||||
|
||||
// Takes a raw OFM style object and returns a new one with glyphs/sprite pointed at the
|
||||
|
||||
Reference in New Issue
Block a user