mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
b7951baf23
- RTL: the measured pills and centred controls use logical forms or a marked line - i18n: the two native widget numbers are positions, not counts (NOT_PLURAL) - Types: styleOverride on the lazy GL map, the location and shared-file payloads, the capabilities fallback, the transport sheet's stay metadata - ESLint: latest-value refs move to layout effects, usePresence keeps the last open state in state, the booking import opens clean with a shared document kept in the list (the reset effect used to clear it again) - Layers: the phone import sheet lives under mobile/ and reads through tripRepo; the offline host check moves to utils/tileUrl - Sizes: plugin layer geometry, hardNavigate and the exit animations get modules of their own - Tests follow the status radios, the stay chip overview, the dock + button for the first list and the field token; store registry lists the new stores
43 lines
2.0 KiB
TypeScript
43 lines
2.0 KiB
TypeScript
import { OFM_DARK, OFM_POSITRON } from '../../constants/mapDefaults';
|
|
import { isNativeIos } from '../../native/platform';
|
|
import { isOfflineForbiddenTemplate, isVectorStyle } from '../../utils/tileUrl';
|
|
import { normalizeStyleForProvider, type GlMapProvider } from './glProviders';
|
|
|
|
/**
|
|
* The basemap a map falls back to offline, so that whatever the user picked
|
|
* online (Mapbox, a raster template, another OpenFreeMap style) they never
|
|
* face a grey map once the connection goes.
|
|
*
|
|
* The two OpenFreeMap styles below are the ones "prepare for offline" stores
|
|
* for every trip, whatever the configured provider (sync/tilePrefetcher.ts):
|
|
* both share one planet tile set, so the dark one only adds its style, sprite
|
|
* and glyphs. A fallback has to be exactly a style that was stored, or its
|
|
* sprite and labels are missing offline.
|
|
*/
|
|
const OFFLINE_STYLES: readonly string[] = [OFM_POSITRON, OFM_DARK];
|
|
|
|
/** The stored style that matches the colour scheme. */
|
|
export function offlineStyleFor(dark: boolean): string {
|
|
return dark ? OFM_DARK : OFM_POSITRON;
|
|
}
|
|
|
|
/**
|
|
* Whether a GL map can be drawn offline as configured. Only MapLibre on one of
|
|
* the stored styles can: Mapbox has nothing stored to draw from, and another
|
|
* OpenFreeMap style lacks its sprite and glyphs offline.
|
|
*/
|
|
export function glWorksOffline(provider: GlMapProvider, maplibreStyle: string | null | undefined): boolean {
|
|
return provider === 'maplibre-gl' && OFFLINE_STYLES.includes(normalizeStyleForProvider('maplibre-gl', maplibreStyle));
|
|
}
|
|
|
|
/**
|
|
* Whether the Leaflet map's basemap can be drawn offline as configured. A
|
|
* stored vector style can. A raster template can where the service worker
|
|
* serves the prefetched tiles, which the iOS app's WebView does not run for a
|
|
* self-hosted server, and never for a host whose tiles may not be stored.
|
|
*/
|
|
export function leafletWorksOffline(tileUrl: string, nativeIos: boolean = isNativeIos()): boolean {
|
|
if (isVectorStyle(tileUrl)) return OFFLINE_STYLES.includes(tileUrl);
|
|
return !nativeIos && !isOfflineForbiddenTemplate(tileUrl);
|
|
}
|