|
| 1 | +# `useStreetViewPanorama` Hook |
| 2 | + |
| 3 | +React hook to use the [Street View Panorama](https://developers.google.com/maps/documentation/javascript/streetview) in any component. |
| 4 | + |
| 5 | +## Usage |
| 6 | +The `StreetViewPanorama` can either be used within a DOM element, like a `<div>` element: |
| 7 | + |
| 8 | +```tsx |
| 9 | +import React, {useEffect} from 'react'; |
| 10 | +import { |
| 11 | + useGoogleMap, |
| 12 | + useStreetViewPanorama |
| 13 | +} from '@ubilabs/google-maps-react-hooks'; |
| 14 | + |
| 15 | +const MyComponent = () => { |
| 16 | +const [divContainer, setDivContainer] = useState<HTMLDivElement | null>(null); |
| 17 | + |
| 18 | + const divRef = useCallback( |
| 19 | + (node: React.SetStateAction<HTMLDivElement | null>) => { |
| 20 | + node && setDivContainer(node); |
| 21 | + }, |
| 22 | + [] |
| 23 | + ); |
| 24 | + |
| 25 | + const map = useGoogleMap(); |
| 26 | + |
| 27 | + const position = /** google.maps.LatLng */; |
| 28 | + const pov = /** google.maps.StreetViewPov */; |
| 29 | + |
| 30 | + const panorama = useStreetViewPanorama({ |
| 31 | + divElement: divContainer, |
| 32 | + position, |
| 33 | + pov |
| 34 | + }); |
| 35 | + |
| 36 | + return <div className={styles.pano} ref={divRef} />; |
| 37 | +}; |
| 38 | +``` |
| 39 | + |
| 40 | +or be created on its own to be used by the map: |
| 41 | + |
| 42 | + |
| 43 | +```tsx |
| 44 | +import React, {useEffect} from 'react'; |
| 45 | +import { |
| 46 | + useGoogleMap, |
| 47 | + useStreetViewPanorama |
| 48 | +} from '@ubilabs/google-maps-react-hooks'; |
| 49 | + |
| 50 | +const MyComponent = () => { |
| 51 | + const position = /** google.maps.LatLng */; |
| 52 | + const pov = /** google.maps.StreetViewPov */; |
| 53 | + |
| 54 | + useStreetViewPanorama({ |
| 55 | + position, |
| 56 | + pov |
| 57 | + }); |
| 58 | + |
| 59 | + return null; |
| 60 | +}; |
| 61 | +``` |
| 62 | +**NOTE**: |
| 63 | +The map instance is only created and can be used with the `useStreetViewPanorama` hook when the `mapContainer` is passed to the `GoogleMapsProvider`. |
| 64 | + |
| 65 | + |
| 66 | +## Return value |
| 67 | + |
| 68 | +Returns a [`StreetViewPanorama`](google.maps.StreetViewPanorama) instance to use directly. |
| 69 | + |
| 70 | +```TypeScript |
| 71 | +google.maps.StreetViewPanorama |
| 72 | +``` |
| 73 | + |
| 74 | +## Parameters |
| 75 | + |
| 76 | +### StreetViewPanoramaProps |
| 77 | + |
| 78 | +Optional options that can be passed to display a street view location: [Street View Locations and Point-of-View (POV)](https://developers.google.com/maps/documentation/javascript/streetview#StreetViewLocation). |
| 79 | + |
| 80 | +```TypeScript |
| 81 | +interface StreetViewPanoramaProps { |
| 82 | + divElement?: HTMLElement | null; |
| 83 | + position?: google.maps.LatLng | google.maps.LatLngLiteral; |
| 84 | + pov?: google.maps.StreetViewPov; |
| 85 | + zoom?: number; |
| 86 | +} |
| 87 | +``` |
0 commit comments