Skip to content

Commit

Permalink
Wait for the tiles to be loaded to display the map
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jan 7, 2025
1 parent 16ec95f commit 9d62788
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion apps/fxc-front/src/app/components/2d/map-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,25 @@ export class MapElement extends connect(store)(LitElement) {
document.addEventListener('visibilitychange', () => this.zoomToTracks(), { once: true });
}

store.dispatch(setApiLoading(false));
// Wait for the tiles to be loaded (or timeout) to hide the splashscreen.
let splashResolve: () => void;
const splashPromise = new Promise<void>((r) => (splashResolve = r));
const to = setTimeout(() => splashResolve(), 4000);
google.maps.event.addListenerOnce(this.map, 'tilesloaded', () => {
splashResolve();
clearTimeout(to);
});
splashPromise.then(() => store.dispatch(setApiLoading(false)));
});
}

disconnectedCallback(): void {
super.disconnectedCallback();
this.subscriptions.forEach((sub) => sub());
this.subscriptions.length = 0;
if (this.map) {
google.maps.event.clearInstanceListeners(this.map);
}
this.map = undefined;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/fxc-front/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"extends": "../../tsconfig.base.json",
"files": [],
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": false,
"module": "ES2020",
"lib": ["ES2020", "DOM", "WebWorker"],
"lib": ["ES2022", "DOM", "WebWorker"],
"moduleResolution": "Bundler",
"strict": true,
"resolveJsonModule": true,
Expand Down

0 comments on commit 9d62788

Please sign in to comment.