Giter VIP home page Giter VIP logo

Comments (4)

BinaryDennis avatar BinaryDennis commented on August 16, 2024 1

Thanks for looking into this issue.

I was assuming that onMapLoaded indicates that the MapView is ready to be used, ie animating viewport changes, start observing events such as location/camera updates etc etc. Therefore I have a spinner as an overlay on the map view until onMapLoaded is called. Thus users cannot interact with the map until such time.

What is the maximum time it can take until this operation is considered fail, and thus onMapLoaded or onMapLoadingError will be called?

The reason Im asking, is because I have waited more than 30 seconds for the callback onMapLoaded but still not received it. And in my experience both as an end-user and app-developer, I dont believe end users will wait longer than that on any UI to be loaded in a mobile context.

So one could also ask, if its good-enough to wait for onStyleLoaded before starting to "work" with the map, then what is the added value that onMapLoaded will give to a dev-user of your API given that it might take quite a long time before that callback is called?

In what scenarios would one need to use onMapLoaded then? If there are no practial scenarios, perhaps it should be removed from the API in order to decrease confusion?

Best Regards
Dennis

from mapbox-maps-ios.

BinaryDennis avatar BinaryDennis commented on August 16, 2024 1

Thank you for that elaborate answer @persidskiy

And thanks for linking to depiction of the general flow of loading.

I will rewrite my code not to wait for onMapLoaded based on your answer then.

👍

from mapbox-maps-ios.

persidskiy avatar persidskiy commented on August 16, 2024

@BinaryDennis Hi, thank you for the report.

This situation may happen when the root StyleJSON is loaded, but some resources like sprites, or tiles aren't loaded yet. Then the engine will try reload them with some backoff.

Most of the time using the onStyleLoaded is safe and may be a better alternative. What's your use-case?

from mapbox-maps-ios.

persidskiy avatar persidskiy commented on August 16, 2024

@BinaryDennis Thank you for the details. I'll try to address your questions.

The map loading process is progressive, meaning the map can be rendered on the screen much sooner than it is "completely loaded" (onMapLoaded event). This way, the end user will see the map as soon as possible, like a web page.

In the worst case scenario, in slow and inconsistent networks, the full load may take minutes. When the network is available, the engine retries loads. This is done because there is no "refresh" button in maps, unlike browsers and our ultimate goal is to render the map.

The loading process itself is quite complicated because the style can have subresources such as images, sources, and other imported styles. Also, the cache may be used. The general idea of the loading flow is demonstrated here https://docs.mapbox.com/ios/maps/api/11.5.0/documentation/mapboxmaps/mapboxmap

At the style loaded stage (onStyleLoaded event), the StyleJSON is loaded and applied, so the engine starts to render it while some parts are still being loaded. The style model is known, so 99.9% of the API is safe to use. In some rare cases when you want to modify the source loaded from the style of something like that, some other event may be used.

I'll comment some of your statements below

I was assuming that onMapLoaded indicates that the MapView is ready to be used, ie animating viewport changes, start observing events such as location/camera updates etc etc.

It's safe to do at any time, even before the style is loaded.

I have a spinner as an overlay on the map view until onMapLoaded is called

It's better to avoid this, or use onStyleLoaded at least.

In general, the API (especially SwiftUI) is designed in a way to allow the developer to just tell the map what to render and not care much about the loading process. For example, the Annotations/Layers/Sources that you put into Map just render as soon as possible, observing the loading process internally. The Viewport API observes the style loading process internally to work with the camera correctly.

In what scenarios would one need to use onMapLoaded then? If there are no practial scenarios, perhaps it should be removed from the API in order to decrease confusion?

One can use it for logging purposes or something else. But we probably will revisit it in the major versions.

from mapbox-maps-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.