OverlayView

Storybook

Open the OverlayView story

OverlayView renders Svelte content inside a map pane at a geographic position, or stretched over geographic bounds. Use it for fully custom HTML overlays.

Props

PropTypeDefaultDescription
positionLatLngInput | nullPoint the content's top-left corner is placed at.
boundsgoogle.maps.LatLngBoundsLiteral | google.maps.LatLngBounds | nullArea the content is stretched over. Takes precedence over position.
panekeyof google.maps.MapPanes'floatPane'Map pane to render into. Use overlayMouseTarget or floatPane for clickable content.
offset[number, number][0, 0]Pixel offset applied to position, as [x, y].
zIndexnumberCSS z-index of the content container.
classstring''Class of the content container.
overlayViewgoogle.maps.OverlayView | nullnullThe instance. Bindable: read it with bind:overlayView.
childrenSnippetOverlay content.

Event Props

PropTypeDescription
onLoad(overlayView: google.maps.OverlayView) => voidCalled once after the overlay is added to the map.

Usage

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

<div style="height: 400px;">
	<APIProvider apiKey="YOUR_API_KEY">
		<GoogleMap center={{ lat: 35.6812, lng: 139.7671 }} zoom={14}>
			<OverlayView
				position={{ lat: 35.6812, lng: 139.7671 }}
				pane="overlayMouseTarget"
				offset={[-60, -40]}
			>
				<div class="label">Tokyo Station</div>
			</OverlayView>
		</GoogleMap>
	</APIProvider>
</div>

<style>
	.label {
		width: 120px;
		padding: 6px;
		text-align: center;
		background: white;
		border-radius: 6px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
	}
</style>
svelte

Notes

  • With position, the content's top-left corner sits on the point; use offset to center it.
  • The content is hidden until the overlay is first drawn, so it never flashes at the top-left of the page.
  • For simple markers with custom HTML, AdvancedMarker with children is usually easier and handles collisions and accessibility.