Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
This repository was archived by the owner on Aug 25, 2023. It is now read-only.

Reasons to reconsider async metadata loading design #36

Closed

Description

I think it would be good to re-visit the design of fetching the TileJSON metadata in MBXMapView rather than MBXMapViewTileOverlay. The present design with asynchronous TileJSON loading followed by swapping out the overlay layer seems to be the root cause of several problems including #8, #18, #29, #24, #30, and #33.

There is a lot of code in MBXMapView which seems to be working around the consequences of swapping out the overlay layers after they are created. Moving TileJSON loading to MBXMapViewTileOverlay should make it possible for a whole bunch of code to just go away, which would hopefully make a lot of stuff work more smoothly.

The design I have in mind is...

  1. Have the first call to loadTileAtPath:result: trigger an asynchronous load of the TileJSON. Until that is finished, all the calls to loadTileAtPath:result: can just invoke result(nil, error). It might also work to just block those threads until the metadata loads, but I'd hesitate to do that. The main Mapbox iOS SDK has a crashing issue with tile loading because it can create too many blocked threads (Numerous duplicate URL tile requests DEPRECATED-mapbox-ios-sdk#206 ). I don't want to replicate that problem.
  2. Step 1 might be all that's necessary, but if not... Add an MKTileOverlayRenderer subclass that uses KVO notifications to keep track of when its associated MBXMapViewTileOverlay has completed loading its TileJSON. Once that happens, it will call its own reloadData method (see https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKTileOverlayRenderer_class/Reference/Reference.html ).

Activity

  1. incanus commented on Feb 18, 2014

    @incanus
    Contributor

    Here is some background on why this async design was done.

    Over in the SDK (http://github.com/mapbox/mapbox-ios-sdk), the tile layer init is blocking with a synchronous network call to fetch TileJSON before returning self. It's not my favorite thing, but it works around the fact that you don't know how to specify min/max zoom, bounding box, attribution info, and other properties that the SDK needs before it can properly treat the layer, so we make sure it's available before then. Since you are likely loading network-based tiles anyway, making an initial request for TileJSON is likely not a problem -- except when it is.

    So, right off the bat, I wanted to avoid such a scenario if possible. The flip side with MBX is that you don't know if the layer canReplaceMapContent, which affects whether Apple's underlying map data is loaded and shown. And on a partial-world coverage overlay, users would expect Apple's to show through, so until you have the TileJSON and know the bounding box, you can't assume they want to always hide it (breaks for partial overlay) or always show it (looks crappy/introduces overhead when you are expecting to replace Apple's maps entirely.) This is the thinking behind

    * @param showDefaultBaseLayer Whether to hide or show Apple's default maps below the MapBox map.
    which lets the user signal intent.

    As to your proposed approach @wsnook, the partial/full/intent issue is still problematic. Merely invoking result(nil, error) ties up your overlay nicely, but doesn't properly handle whether Apple should be showing or not.

    Maybe we just ditch all attempts at automatically determining this?

  2. incanus commented on Feb 18, 2014

    @incanus
    Contributor

    One way to address this would be to switch the default MBXMapViewTileOverlay initializer to use a tileJSON string (see #25) and factor the TileJSON fetching code out to a separate class.

    I think this just adds complexity because:

    • Now you have to know what TileJSON is and where to get it from. Also why.
    • You still have to pass that TileJSON back up to the map view at the time that you really need a map view. Sync/async problem still exists.

    favoring power and flexibility over simplicity of invocation might be a reasonable thing to do.

    This is our SDK :-P

    I'm starting to lean towards:

    Maybe we just ditch all attempts at automatically determining this?

    The BOOL in there now may be enough. Very worst case, you don't get the exact result you want by default and so you change the BOOL and try again. That lets us add the overlay immediately and synchronously, but not require the developer to care about when that stops rendering empty and starts rendering drawn tiles (once it knows how).

  3. incanus commented on Feb 18, 2014

    @incanus
    Contributor

    Yeah, I like approach of hitting the stuff already on deck first. I think we're on the same page as to where this should go API design-wise so let's hit it in a future milestone.

  4. incanus commented on Feb 19, 2014

    @incanus
    Contributor

    "You get a blank grid until the TileJSON has loaded".

    I'm just not positive that the Apple map then loads if the TileJSON says the overlay is partial coverage. I'm not sure the changing of canReplaceMapContent triggers the base map in this way, but it needs to be tested.

  5. added this to the 0.3.0 milestone on Feb 19, 2014
  6. ghost closed this as completedon Mar 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions