66 Children will mount once the map is fully loaded.
77
88 ```svelte
9- <MapLibre>
9+ <MapLibre mapProvider="open-street">
10+ <MapLibreMarker lngLat={{ lng: 0, lat: 0 }} />
11+ </MapLibre>
12+ ```
13+
14+ ```svelte
15+ <MapLibre mapProvider="google-maps" mapProviderKey="mycoolkey">
1016 <MapLibreMarker lngLat={{ lng: 0, lat: 0 }} />
1117 </MapLibre>
1218 ```
@@ -18,8 +24,9 @@ import 'maplibre-gl/dist/maplibre-gl.css';
1824import { onMount , tick } from ' svelte' ;
1925import { provideMapContext } from ' ./hooks' ;
2026import { Map , type MapOptions } from ' maplibre-gl' ;
21- import { style } from ' ./style' ;
27+ import { getStyleSpecification } from ' ./style' ;
2228import { LngLat } from ' $lib' ;
29+ import { MapProviders , type MapProvider } from ' ./types' ;
2330
2431/** The minimum camera pitch. */
2532export let minPitch = 0 ;
@@ -49,6 +56,20 @@ export let map: Map | undefined = undefined;
4956
5057export let options: Partial <MapOptions > | undefined = undefined ;
5158
59+ /**
60+ * The map provider to use.
61+ *
62+ * @default ' open-street'
63+ */
64+ export let mapProvider: MapProvider = MapProviders .openStreet ;
65+
66+ /**
67+ * The API key for the map provider.
68+ *
69+ * @default undefined
70+ */
71+ export let mapProviderKey: string | undefined = undefined ;
72+
5273/** Fired after the map has been created. */
5374export let onCreate: undefined | ((map : Map ) => void ) = undefined ;
5475
@@ -109,7 +130,7 @@ onMount(() => {
109130 map = new Map ({
110131 antialias: true ,
111132 container ,
112- style ,
133+ style: getStyleSpecification ( mapProvider , mapProviderKey ) ,
113134 center ,
114135 zoom ,
115136 minPitch ,
@@ -136,6 +157,7 @@ $: map?.setMinPitch(minPitch);
136157$ : map ?.setMaxPitch (maxPitch );
137158$ : map ?.setZoom (zoom );
138159$ : map ?.setCenter (center );
160+ $ : map ?.setStyle (getStyleSpecification (mapProvider , mapProviderKey ));
139161 </script >
140162
141163{#if created }
0 commit comments