Skip to content

Commit

Permalink
Bugfix for map flashing issue 🤞🏻
Browse files Browse the repository at this point in the history
  • Loading branch information
braddf committed Feb 23, 2024
1 parent 9a47351 commit 56b4d57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions apps/nowcasting-app/components/helpers/mapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ export const safelyUpdateMapData = (
!map.isStyleLoaded()
) {
if (!map.isStyleLoaded()) {
setTimeout(() => {
// console.log("map is not style loaded, trying again");
// Check if we've already set a timeout for this map
const existingTimeout = localStorage.getItem(
`MapTimeoutId-${map.getContainer().dataset.title}`
);
// If we have, clear it
if (existingTimeout) {
// console.log(`clearing existing map timeout for ${map.getContainer().dataset.title}`);
clearTimeout(Number(existingTimeout));
}
// Set a new timeout to check if the map is ready and update the data
// console.log(`setting new map timeout for ${map.getContainer().dataset.title}`, newTimeout);
const newTimeout = setTimeout(() => {
// console.warn("map is not style loaded, trying again");
safelyUpdateMapData(map, updateMapData);
}, 400);
}, 500);
// Save the timeout id to local storage
localStorage.setItem(
`MapTimeoutId-${map.getContainer().dataset.title}`,
newTimeout.toString()
);
}
return;
} else {
Expand Down
1 change: 1 addition & 0 deletions apps/nowcasting-app/components/map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface IMap {
controlOverlay: any;
bearing?: number;
updateData: { newData: boolean | string; updateMapData: (map: mapboxgl.Map) => void };
children: React.ReactNode;
title: string;
}

0 comments on commit 56b4d57

Please sign in to comment.