fix(map): use stored basemaps for uncached GL raster hosts

Share the service-worker raster match with prefetch and the offline renderer. Keep an allowed custom host online and switch to the stored basemap offline when its tiles are outside the readable cache.
This commit is contained in:
Maurice
2026-12-06 16:04:31 +01:00
parent f394818f40
commit dcbabe998b
5 changed files with 39 additions and 16 deletions
+2 -9
View File
@@ -33,7 +33,7 @@ import { clearVectorCache, prefetchStyleAssets, prefetchVectorForPlaces } from '
import { isNativeIos } from '../native/platform'
import { isIosDevice } from '../utils/iosDevice'
import { openCacheStorage } from './openCacheStorage'
import { GL_TILE_CACHE, isGlRasterTileRequest } from './glTileCache'
import { GL_TILE_CACHE, hasGlRasterCache } from './glTileCache'
import { useSettingsStore } from '../store/settingsStore'
import { MAPLIBRE_FROM_TEMPLATE } from '@trek/shared'
@@ -308,14 +308,7 @@ async function openTileCache(cacheName: string = TILE_CACHE): Promise<Cache | nu
*/
function fetchedAsGl(template: string): boolean {
const { map_provider: provider, maplibre_style: style } = useSettingsStore.getState().settings
if (provider !== 'maplibre-gl' || style !== MAPLIBRE_FROM_TEMPLATE) return false
try {
const url = new URL(template.replace(/\{s\}/g, 'a'))
// The service worker's own matcher, asked about a CORS request for this host.
return isGlRasterTileRequest({ url, request: { mode: 'cors' } as Request })
} catch {
return false
}
return provider === 'maplibre-gl' && style === MAPLIBRE_FROM_TEMPLATE && hasGlRasterCache(template)
}
/**