In this code sandbox, I have some markers with InfoBox nested in the marker that is shown on click. How can I also show that InfoBox when switching into the StreetView mode?
// The imports
import { GoogleMap, InfoBox, Marker, OverlayView, Polyline, useJsApiLoader } from '@react-google-maps/api';
{data.map(({ source, destination, distance }, index) => (
<Marker key={index} position={source}>
<InfoBox
options={{
enableEventPropagation: true,
boxStyle: {...}
}}
>
<div
style={{...}}
>
<p>Some text here</p>
</div>
</InfoBox>
</Marker>
))}
Note: No API key is provided in the code sandbox. Providing the API key will show the StreetView icon that can be dragged-dropped on the map close to a Marker.
Replace the
Mapin calls to theInfoWindow#openmethod with aStreetViewPanoramaIn Google's documentation for the Maps JavaScript API on overlays within street view, it is noted that an
InfoWindowmay be opened within aStreetViewPanoramaby passing theStreetViewPanoramainstead of aMapwhen calling theopen()method.In the
@react-google-maps/apicodebase, theInfoWindow.tsxfile gets theMapinstance through React's Context API and uses it to open theInfoWindowinstance:With that, we can import
MapContextand wrap our<InfoWindow>with it to replace themapwith aStreetViewPanoramainstance, which we can get by using<StreetViewPanorama>'sonLoadevent.View this example live at CodeSandbox.