Skip to content

Check if map is loaded! #405

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

You must be logged in to vote

Currently, you can only check if the Maps JavaScript API is loaded using the useApiIsLoaded hook.
If you want to wait until the map is fully rendered, you can use an overlay and the tilesloaded or idle events, roughly like this:

const MyMap = () => {
  const [mapIsReady, setMapIsReady] = useState(false);
  const handleTilesLoaded = useCallback(() => setMapIsReady(true), []);

  return <>
    <Map onTilesLoaded={handleTilesLoaded}>...</Map>
    {!mapIsReady && <div className="loading-overlay"></div>}
  </>;
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@anxheloo
Comment options

Answer selected by usefulthink
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