Skip to content

How to enable or disable traffic in my map? #388

Answered by usefulthink
anxheloo asked this question in Q&A
Discussion options

You must be logged in to vote

One way would be to create a component for that:

const TrafficLayer = () => {
  const map = useMap();

  useEffect(() => {
    if(!map) return;

    const trafficLayer = new google.maps.TrafficLayer({map, autoRefresh: false});
    return () => { trafficLayer.setMap(null); };
  }, [map]);

  return <></>;
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@anxheloo
Comment options

@anxheloo
Comment options

Answer selected by anxheloo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants