From 49fa3ae3c166232fd2c8ed2ce189092508713316 Mon Sep 17 00:00:00 2001 From: Florian Sommariva <1926041+dtrucs@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:46:23 +0100 Subject: [PATCH] Define bounds instead of minZoom for tileLayerOffline --- frontend/src/services/offline/injectOfflineMode.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/src/services/offline/injectOfflineMode.ts b/frontend/src/services/offline/injectOfflineMode.ts index d33d7403a..469b5fc39 100644 --- a/frontend/src/services/offline/injectOfflineMode.ts +++ b/frontend/src/services/offline/injectOfflineMode.ts @@ -1,4 +1,4 @@ -import L, { LatLngBoundsExpression, Layer, Map } from 'leaflet'; +import L, { LatLngBoundsExpression, LatLngExpression, Layer, Map } from 'leaflet'; import CacheManager from 'services/offline/CacheManager'; import { getMapConfig } from 'components/Map/config'; @@ -6,8 +6,8 @@ import { ControlSaveTiles, getStorageInfo, getStoredTilesAsJson, - savetiles as Lsavetiles, tileLayerOffline as LtileLayerOffline, + savetiles, TileLayerOffline, } from 'leaflet.offline'; @@ -16,20 +16,18 @@ type EventStorageSize = TileLayerOffline & { }; const injectOfflineMode = (map: Map, id: number, bounds: LatLngBoundsExpression) => { - const mapConfig = getMapConfig(); - - const { mapOfflineLayer, mapClassicLayers, zoomAvailableOffline } = mapConfig; + const { mapOfflineLayer, mapClassicLayers, zoomAvailableOffline } = getMapConfig(); const tileLayerOffline = LtileLayerOffline(`${mapOfflineLayer.url}?${id}`, { attribution: mapOfflineLayer?.options?.attribution, subdomains: 'abc', - minZoom: Math.min(...(zoomAvailableOffline ?? [])), }); tileLayerOffline.addTo(map); - const controlInstance: ControlSaveTiles = Lsavetiles(tileLayerOffline, { - zoomlevels: mapConfig.zoomAvailableOffline, + const controlInstance: ControlSaveTiles = savetiles(tileLayerOffline, { + zoomlevels: zoomAvailableOffline, + bounds: bounds ? L.latLngBounds(bounds as [LatLngExpression, LatLngExpression]) : null, confirm(_layer: Layer, successCallback: () => void) { successCallback(); },