GroundOverlay

Storybook

Open the GroundOverlay story

GroundOverlay stretches an image over a geographic area with google.maps.GroundOverlay.

Props

PropTypeDefaultDescription
urlstring(required)Image URL. Changing it recreates the overlay.
boundsgoogle.maps.LatLngBoundsLiteral | google.maps.LatLngBounds(required)Area the image covers. Changing it recreates the overlay.
opacitynumber1Opacity between 0 and 1. Updated in place.
clickablebooleantrueWhether the overlay handles mouse events. Read when the overlay is created.
groundOverlaygoogle.maps.GroundOverlay | nullnullThe instance. Bindable: read it with bind:groundOverlay.

Event Props

PropTypeDescription
onClick(event: google.maps.MapMouseEvent) => voidclick
onDblClick(event: google.maps.MapMouseEvent) => voiddblclick
onLoad(groundOverlay: google.maps.GroundOverlay) => voidCalled each time the overlay is created.

Usage

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

	const url =
		'https://developers.google.com/maps/documentation/javascript/examples/full/images/talkeetna.png';
	const bounds = { north: 62.4, south: 62.281819, east: -150.005, west: -150.287132 };
	let opacity = $state(0.6);
</script>

<input type="range" min="0" max="1" step="0.05" bind:value={opacity} />

<div style="height: 400px;">
	<APIProvider apiKey="YOUR_API_KEY">
		<GoogleMap center={{ lat: 62.34, lng: -150.15 }} zoom={11}>
			<GroundOverlay {url} {bounds} {opacity} />
		</GoogleMap>
	</APIProvider>
</div>
svelte

Notes

  • The Maps API cannot change the image or bounds of an existing overlay, so changing url or bounds removes the old overlay and creates a new one (and calls onLoad again).