mirror of
https://github.com/FoggedLens/deflock.git
synced 2026-08-16 15:40:23 +02:00
do not repeat fetch
This commit is contained in:
@@ -13,6 +13,7 @@ export const useTilesStore = defineStore('tiles', () => {
|
|||||||
const tiles: Ref<Record<string, ALPR[]>> = ref({});
|
const tiles: Ref<Record<string, ALPR[]>> = ref({});
|
||||||
const availableTiles: Ref<string[]> = ref([]);
|
const availableTiles: Ref<string[]> = ref([]);
|
||||||
const expirationDateUtc: Ref<Date | null> = ref(null);
|
const expirationDateUtc: Ref<Date | null> = ref(null);
|
||||||
|
const fetchingTiles = new Set<string>();
|
||||||
let tileUrlTemplate: string|undefined = undefined;
|
let tileUrlTemplate: string|undefined = undefined;
|
||||||
let tileSizeDegrees: number|undefined = undefined;
|
let tileSizeDegrees: number|undefined = undefined;
|
||||||
|
|
||||||
@@ -32,6 +33,11 @@ export const useTilesStore = defineStore('tiles', () => {
|
|||||||
const fetchAndAddTile = async (lat: number, lng: number): Promise<void> => {
|
const fetchAndAddTile = async (lat: number, lng: number): Promise<void> => {
|
||||||
const key = `${lat}/${lng}`;
|
const key = `${lat}/${lng}`;
|
||||||
|
|
||||||
|
if (fetchingTiles.has(key)) {
|
||||||
|
console.debug(`Tile ${key} is already being fetched, skipping fetch`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (tiles.value[key]) {
|
if (tiles.value[key]) {
|
||||||
console.debug(`Tile ${key} is already cached, skipping fetch`);
|
console.debug(`Tile ${key} is already cached, skipping fetch`);
|
||||||
return;
|
return;
|
||||||
@@ -42,9 +48,16 @@ export const useTilesStore = defineStore('tiles', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const url = tileUrlTemplate.replace('{lat}/{lon}', key);
|
const url = tileUrlTemplate.replace('{lat}/{lon}', key);
|
||||||
const tile = await api.get(url);
|
|
||||||
|
|
||||||
tiles.value[key] = tile.data;
|
try {
|
||||||
|
fetchingTiles.add(key);
|
||||||
|
const tile = await api.get(url);
|
||||||
|
tiles.value[key] = tile.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to fetch tile ${key}:`, error);
|
||||||
|
} finally {
|
||||||
|
fetchingTiles.delete(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchVisibleTiles = async (boundingBox: BoundingBox): Promise<void> => {
|
const fetchVisibleTiles = async (boundingBox: BoundingBox): Promise<void> => {
|
||||||
|
|||||||
@@ -171,7 +171,6 @@ function updateMarkers() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Fetching visible tiles');
|
|
||||||
fetchVisibleTiles(bounds.value);
|
fetchVisibleTiles(bounds.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user