Feature(offline): add auto install for offline basemaps

This commit is contained in:
Pieter Vander Vennet 2025-07-31 12:33:03 +02:00
parent 2dd0240ce8
commit 55ef862027
2 changed files with 13 additions and 2 deletions

View file

@ -7,7 +7,7 @@
"attribution": "<a href=\"https://github.com/protomaps/basemaps\">Protomaps</a> © <a href=\"https://openstreetmap.org\">OpenStreetMap</a>",
"type": "vector",
"tiles": [
"https://127.0.0.1:1234/service-worker/offline-basemap/{z}-{x}-{y}.mvt?fallback=true"
"https://127.0.0.1:1234/service-worker/offline-basemap/{z}-{x}-{y}.mvt?fallback=true&auto=true"
],
"maxzoom": 15,
"minzoom": 0

View file

@ -321,7 +321,18 @@ export class OfflineBasemapManager {
if (this.metaCached.length === 0) {
await this.updateCachedMeta()
}
const area = this.determineArea(z, x, y)
let area = this.determineArea(z, x, y)
if (options?.autoInstall && !area) {
// We attempt to install the local files
const candidates = this.getInstallCandidates({ z, x, y })
for (const candidate of candidates) {
await this.installArea(candidate)
}
await this.updateCachedMeta()
area = this.determineArea(z, x, y)
}
if (!area) {
if (options?.fallback) {
return this.getFallback(z, x, y)