Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify documentation for map.loaded(), map.isStyleLoaded() #6708

Open
anandthakker opened this issue May 22, 2018 · 5 comments
Open

Clarify documentation for map.loaded(), map.isStyleLoaded() #6708

anandthakker opened this issue May 22, 2018 · 5 comments
Assignees

Comments

@anandthakker
Copy link
Contributor

mapbox-gl-js version: 0.45.0

Refs #6707

The documentation for map.loaded() and map.isStyleLoaded() do not make it clear what the difference is between them.

    /**
     * Returns a Boolean indicating whether the map is fully loaded.
     *
     * Returns `false` if the style is not yet fully loaded,
     * or if there has been a change to the sources or style that
     * has not yet fully loaded.
     *
     * @returns {boolean} A Boolean indicating whether the map is fully loaded.
     */
    loaded()
    /**
     * Returns a Boolean indicating whether the map's style is fully loaded.
     *
     * @returns {boolean} A Boolean indicating whether the style is fully loaded.
     */
    isStyleLoaded()

It should be clear from reading the docs:

  • What "fully loaded" means / what might cause it to be not true.
  • Under what conditions map.loaded() !== map.isStyleLoaded()
@mike-marcacci
Copy link
Contributor

I agree that some clarification would be helpful here. My initial assumption was that isStyleLoaded() would return false before the initial load and between a styledataloading event and subsequent styledata event, indicating that layers were not ready for queries. However, it appears to return false under a far wider range of conditions.

@stevage
Copy link
Contributor

stevage commented Jun 21, 2018

IMHO the important thing to include here is the implications of the current state: can you add sources, can you change paint or layout properties, can you manipulate the state otherwise.

@mourner
Copy link
Member

mourner commented Jul 25, 2018

Related: #5052, which stems from the same confusion over what map.loaded() means.

@hyperknot
Copy link

hyperknot commented May 15, 2020

Is there a reference document about a map's lifecycle events? I'd like to know how are

  • map.loaded()
  • map.isStyleLoaded()
  • map.on('load')
  • map.on('idle')
  • map.on('style.load')

connected on each other during the lifecycle of map.

Namely, is such a recursive setTimeout loop needed today?
#2268 (comment)

@ollyde
Copy link

ollyde commented Feb 20, 2021

A quick example of how I do it, but an isLoaded call back would be great!

const goToLocation = (mapEvent: MapboxGl.Map) => {
        if (mapEvent.loaded()) {
            map.resize()
            map.flyTo({ center: [10.7522, 59.9139], animate: false, zoom: 13 })
        }
    }

    return (
        <Map
            style="mapbox://styles/mapbox/dark-v10"
            center={[10.7522, 59.9139]}
            onStyleLoad={(map) => goToLocation(map)}
        />
    );

@domlet domlet self-assigned this Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants