You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
Reasons to reconsider async metadata loading design #36
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...
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.
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?
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).
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.
"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.
Activity
incanus commentedon Feb 18, 2014
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
initis blocking with a synchronous network call to fetch TileJSON before returningself. 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 behindmbxmapkit/MBXMapKit.h
Line 34 in 31be040
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?
incanus commentedon Feb 18, 2014
I think this just adds complexity because:
This is our SDK :-P
I'm starting to lean towards:
The
BOOLin there now may be enough. Very worst case, you don't get the exact result you want by default and so you change theBOOLand 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).incanus commentedon Feb 18, 2014
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.
incanus commentedon Feb 19, 2014
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
canReplaceMapContenttriggers the base map in this way, but it needs to be tested.