mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user