StreetViewPanorama

A component to display Street View panoramas.

Must be used within an <APIProvider> component.

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

  let panorama: google.maps.StreetViewPanorama | null = null;

  const position = { lat: 40.729884, lng: -73.990988 }; // Example: Near Washington Square Park
</script>

<APIProvider apiKey={GOOGLE_MAPS_API_KEY}>
  <div style="height: 600px; width: 100%;">
    <!-- You can either display the map and link the panorama to it -->
    <GoogleMap initialCenter={position} initialZoom={14}>
       <StreetViewPanorama bind:panorama {position} />
    </GoogleMap>

    <!-- Or display the panorama directly -->
    <!-- <div style="height: 600px; width: 100%;">
      <StreetViewPanorama {position} />
    </div> -->
  </div>
</APIProvider>

<button on:click={() => panorama?.setZoom(panorama.getZoom()! + 1)}>Zoom In</button>
svelte

Props

PropTypeDefaultDescription
optionsgoogle.maps.StreetViewPanoramaOptions | undefinedundefinedInitialization options for the panorama. Takes precedence over individual props.
containerIdstring | undefinedundefinedThe ID for the div element that displays the panorama.
containerClassstring''The class name for the div element that displays the panorama.
containerStylestring'width:100%;height:100%;'The style for the div element that displays the panorama.
positiongoogle.maps.LatLng | google.maps.LatLngLiteral | undefinedundefinedThe initial position for the panorama.
povgoogle.maps.StreetViewPov | undefinedundefinedThe initial Point of View for the panorama.
zoomnumber | undefinedundefinedThe initial zoom level for the panorama.
panostring | undefinedundefinedThe specific panorama ID to display. Takes precedence over position.
addressControlboolean | undefinedundefinedWhether to display the address control.
enableCloseButtonboolean | undefinedundefinedWhether to display the close button.
fullscreenControlboolean | undefinedundefinedWhether to display the fullscreen control.
imageDateControlboolean | undefinedundefinedWhether to display the image date control.
linksControlboolean | undefinedundefinedWhether to display the links control.
motionTrackingboolean | undefinedundefinedWhether to enable motion tracking.
motionTrackingControlboolean | undefinedundefinedWhether to display the motion tracking control.
panControlboolean | undefinedundefinedWhether to display the pan control.
scrollwheelboolean | undefinedundefinedWhether to enable zooming via the scroll wheel.
zoomControlboolean | undefinedundefinedWhether to display the zoom control.
visiblebooleantrueWhether the panorama is initially visible.

Events

EventTypeDescription
onCloseClick(() => void) | undefinedFired when the close button is clicked.
onPanoChanged(() => void) | undefinedFired when the panorama ID changes.
onPositionChanged(() => void) | undefinedFired when the panorama position changes.
onPovChanged(() => void) | undefinedFired when the panorama Point of View (pov) changes.
onResize(() => void) | undefinedFired when the panorama size changes.
onStatusChanged(() => void) | undefinedFired when the panorama loading status changes.
onVisibleChanged(() => void) | undefinedFired when the panorama visibility changes.
onZoomChanged(() => void) | undefinedFired when the panorama zoom level changes.
onLoad((panorama: google.maps.StreetViewPanorama) => void) | undefinedFired when the panorama is loaded. Receives the instance.
onUnmount((panorama: google.maps.StreetViewPanorama) => void) | undefinedFired when the component is destroyed. Receives the instance.

Binding

You can access the google.maps.StreetViewPanorama instance using bind:panorama.

<script lang="ts">
  import { StreetViewPanorama } from 'svelte-google-maps-api';
  let panorama: google.maps.StreetViewPanorama | null = null;
</script>

<StreetViewPanorama bind:panorama />

<button disabled={!panorama} on:click={() => panorama?.setZoom(1)}>
  Reset Zoom
</button>
svelte