TrafficLayer

Storybook

Open the TrafficLayer story

TrafficLayer shows real-time traffic conditions with google.maps.TrafficLayer. Render it inside GoogleMap to show the layer and remove it to hide the layer.

Props

PropTypeDefaultDescription
autoRefreshbooleantrueRefresh traffic data automatically.

Event Props

PropTypeDescription
onLoad(layer: google.maps.TrafficLayer) => voidCalled once after the layer is added to the map.

Usage

<script lang="ts">
	import { APIProvider, GoogleMap, TrafficLayer } from 'svelte-google-maps-api';

	let visible = $state(true);
</script>

<label><input type="checkbox" bind:checked={visible} /> Show layer</label>

<div style="height: 400px;">
	<APIProvider apiKey="YOUR_API_KEY">
		<GoogleMap center={{ lat: 35.6812, lng: 139.7671 }} zoom={13}>
			{#if visible}
				<TrafficLayer autoRefresh />
			{/if}
		</GoogleMap>
	</APIProvider>
</div>
svelte

Notes

  • Traffic data is not available in every region.