HeatmapLayer

A component to display a heatmap layer on the map. Requires the visualization library. Please specify libraries={['visualization']} in the <APIProvider> props.

Must be used within a <GoogleMap> component.

<script lang="ts">
  import { APIProvider, GoogleMap, HeatmapLayer } from 'svelte-google-maps-api';
  import { GOOGLE_MAPS_API_KEY } from '$env/static/private';

  // Example data (points of interest in San Francisco)
  const heatmapData = [
    { location: { lat: 37.7749, lng: -122.4194 }, weight: 3 }, // Downtown SF
    { location: { lat: 37.7831, lng: -122.4039 }, weight: 2 }, // Union Square area
    { location: { lat: 37.7955, lng: -122.3937 }, weight: 1 }, // Ferry Building
    { location: { lat: 37.7694, lng: -122.4862 }, weight: 2 }, // Golden Gate Park
    { location: { lat: 37.8270, lng: -122.4230 }, weight: 3 }  // Alcatraz (visible from mainland)
    // Add more data points as needed
  ];
</script>

<APIProvider apiKey={GOOGLE_MAPS_API_KEY} libraries={['visualization']}>
  <GoogleMap initialCenter={{ lat: 37.7749, lng: -122.4194 }} initialZoom={13}>
    <HeatmapLayer data={heatmapData} radius={20} />
  </GoogleMap>
</APIProvider>
svelte

Props

PropTypeDefaultDescription
dataInputHeatmapData | undefinedundefinedThe data for the heatmap. Accepts formats: WeightedLocation[], { location: LatLngLiteral; weight: number }[], (LatLng | LatLngLiteral)[], or MVCArray. LatLngLiteral is automatically converted to LatLng.
optionsgoogle.maps.visualization.HeatmapLayerOptions | undefinedundefinedInitialization options for the heatmap layer. Takes precedence over individual props.
dissipatingboolean | undefinedundefinedWhether the heatmap dissipates on zoom.
gradientstring[] | undefinedundefinedThe color gradient of the heatmap. An array of CSS color strings (e.g., rgba(102, 255, 0, 0), rgba(147, 255, 0, 1)).
maxIntensitynumber | undefinedundefinedThe maximum intensity of the heatmap. Defaults to the highest density of points at any particular pixel on the map.
opacitynumber | undefinedundefinedThe opacity of the heatmap (from 0 to 1).
radiusnumber | undefinedundefinedThe radius of influence for each data point, in pixels.

InputHeatmapData Type:

type InputHeatmapData =
  | google.maps.visualization.WeightedLocation[]
  | { location: google.maps.LatLngLiteral; weight: number }[]
  | (google.maps.LatLng | google.maps.LatLngLiteral)[]
  | google.maps.MVCArray<
      google.maps.visualization.WeightedLocation | google.maps.LatLng | google.maps.LatLngLiteral
    >;
typescript

Events

EventTypeDescription
onLoad((heatmapLayer: google.maps.visualization.HeatmapLayer) => void) | undefinedFired when the layer is loaded. Receives the instance.
onUnmount((heatmapLayer: google.maps.visualization.HeatmapLayer) => void) | undefinedFired when the component is destroyed. Receives the instance.

Binding

This component does not support the bind: directive.