Add transit layer in <Map/> #440
-
Hello, I'm working with '@vis.gl/react-google-maps' and AdvancedMarker. I'm trying to add a transit layer to my map, but I can't find a way to do it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can roughly follow this guide here: https://visgl.github.io/react-google-maps/docs/guides/interacting-with-google-maps-api#hooks For example, you create a const TransitLayer = () => {
const map = useMap();
useEffect(() => {
if (!map) return;
const transitLayer = new google.maps.TransitLayer();
transitLayer.setMap(map);
return () => transitLayer.setMap(null);
}, [map]);
return <></>;
} (since this component doesn't need to render anything, it would look almost the same as a custom hook |
Beta Was this translation helpful? Give feedback.
You can roughly follow this guide here: https://visgl.github.io/react-google-maps/docs/guides/interacting-with-google-maps-api#hooks
For example, you create a
TransitLayer
component and use theuseMap
/useEffect
construct to add the transitLayer:(since this component doesn't need to render anything, it would look almost the same as a custom hook
useTransitLayer
if you prefer it that way)