Skip to content

Commit

Permalink
Define bounds instead of minZoom for tileLayerOffline
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Jan 6, 2025
1 parent f501c8c commit 49fa3ae
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions frontend/src/services/offline/injectOfflineMode.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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';

import {
ControlSaveTiles,
getStorageInfo,
getStoredTilesAsJson,
savetiles as Lsavetiles,
tileLayerOffline as LtileLayerOffline,
savetiles,
TileLayerOffline,
} from 'leaflet.offline';

Expand All @@ -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();
},
Expand Down

0 comments on commit 49fa3ae

Please sign in to comment.