Skip to content

Commit 40c8ae7

Browse files
performace boost in map loading 🗺️ & Enhanced Stop Details with Interactive Map
1 parent 54c1e36 commit 40c8ae7

File tree

5 files changed

+1021
-350
lines changed

5 files changed

+1021
-350
lines changed

src/components/MapContainer.svelte

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
import FullPageLoadingSpinner from '$components/FullPageLoadingSpinner.svelte';
77
import { env } from '$env/dynamic/public';
88
import { PUBLIC_OBA_MAP_PROVIDER } from '$env/static/public';
9-
import { onMount } from 'svelte';
109
import { MapSource } from './../config/mapSource.js';
11-
12-
let apiKey = env.PUBLIC_OBA_GOOGLE_MAPS_API_KEY;
10+
11+
1312
let { handleStopMarkerSelect, mapProvider = $bindable(), ...restProps } = $props();
14-
15-
onMount(() => {
13+
14+
// memoize provider creation to avoid unnecessary instantiations 🙅
15+
$effect(() => {
16+
const apiKey = env.PUBLIC_OBA_GOOGLE_MAPS_API_KEY;
17+
1618
if (PUBLIC_OBA_MAP_PROVIDER === MapSource.Google) {
1719
mapProvider = new GoogleMapProvider(apiKey, handleStopMarkerSelect);
1820
} else if (PUBLIC_OBA_MAP_PROVIDER === MapSource.OpenStreetMap) {
1921
mapProvider = new OpenStreetMapProvider(handleStopMarkerSelect);
2022
} else {
21-
console.error('Unknown map provider:');
23+
console.error('Unknown map provider:', PUBLIC_OBA_MAP_PROVIDER);
2224
}
2325
});
2426
</script>
@@ -27,4 +29,4 @@
2729
<MapView {handleStopMarkerSelect} {mapProvider} {...restProps} />
2830
{:else}
2931
<FullPageLoadingSpinner />
30-
{/if}
32+
{/if}

0 commit comments

Comments
 (0)