Circle

Storybook

Open the Circle story

Circle draws a google.maps.Circle. With editable or draggable, the new center and radius flow back through bind:center and bind:radius.

Props

PropTypeDefaultDescription
centergoogle.maps.LatLngLiteral | google.maps.LatLngCircle center. Bindable.
radiusnumberRadius in meters. Bindable.
strokeColorstringStroke color.
strokeOpacitynumberStroke opacity between 0 and 1.
strokeWeightnumberStroke width in pixels.
strokePositiongoogle.maps.StrokePositionStroke position (CENTER, INSIDE, OUTSIDE).
fillColorstringFill color.
fillOpacitynumberFill opacity between 0 and 1.
clickablebooleanWhether the shape handles mouse events.
draggablebooleanLets the user drag the shape.
editablebooleanShows handles so the user can edit the shape.
visiblebooleanWhether the shape is visible.
zIndexnumberStacking order.
optionsgoogle.maps.CircleOptionsOther circle options. Individual props override these.
circlegoogle.maps.Circle | nullnullThe instance. Bindable: read it with bind:circle.

Event Props

PropTypeDescription
onClick(event: google.maps.MapMouseEvent) => voidclick
onDblClick(event: google.maps.MapMouseEvent) => voiddblclick
onContextMenu(event: google.maps.MapMouseEvent) => voidcontextmenu
onMouseDown(event: google.maps.MapMouseEvent) => voidmousedown
onMouseUp(event: google.maps.MapMouseEvent) => voidmouseup
onMouseOver(event: google.maps.MapMouseEvent) => voidmouseover
onMouseOut(event: google.maps.MapMouseEvent) => voidmouseout
onMouseMove(event: google.maps.MapMouseEvent) => voidmousemove
onDragStart(event: google.maps.MapMouseEvent) => voiddragstart
onDrag(event: google.maps.MapMouseEvent) => voiddrag
onDragEnd(event: google.maps.MapMouseEvent) => voiddragend
onCenterChanged(center: google.maps.LatLngLiteral) => voidcenter_changed
onRadiusChanged(radius: number) => voidradius_changed
onLoad(circle: google.maps.Circle) => voidCalled once after the circle is created.

Usage

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

	let center = $state({ lat: 35.6812, lng: 139.7671 });
	let radius = $state(1000);
</script>

<div style="height: 400px;">
	<APIProvider apiKey="YOUR_API_KEY">
		<GoogleMap center={{ lat: 35.6812, lng: 139.7671 }} zoom={13}>
			<Circle bind:center bind:radius fillColor="#f59e0b" fillOpacity={0.2} strokeColor="#f59e0b" editable draggable />
		</GoogleMap>
	</APIProvider>
</div>

<p>Radius: {Math.round(radius)} m</p>
svelte