Using the google-map-react package, I've created a MapView
component in TypeScript as follows.
export function MapView<I extends Mappable>({ getData }: MapViewProps<I>): JSX.Element {
const [mapZoom, setMapZoom] = useState(5);
const [mapBounds, setMapBounds] = useState<[number, number, number, number]>([-1, -1, -1, -1]);
return (
<div className="map-container">
<GoogleMapReact
bootstrapURLKeys={{ key: "API_KEY" }}
defaultCenter={{
lat: 39.381266,
lng: -97.922211,
}}
zoom={mapZoom}
options={{ maxZoom: 10 }}
onChange={({ zoom, bounds }) => {
setMapZoom(zoom);
setMapBounds([bounds.nw.lng, bounds.se.lat, bounds.se.lng, bounds.nw.lat]);
}}
/>
</div>
);
}
I want to make the map slowly scroll horizontally if the user has not yet touched the map. My first thought was to add a useEffect
that automatically updates the bounds, but that doesn't seem ideal. Any thoughts?