mapbox/mapbox-ios-sdk — pull request #397 by boundsj (2014-02-21 08:13:30+00:00)
Title: Better async map view pattern

With regards to #286 and your comments about #395, please find attached more food for thought.

These changes still need some polish but I wanted to get your thoughts before continuing. This attempt takes inspiration from mapkit and adds two new delegate callbacks to RMMapViewDelegate `- (void)mapViewWillStartLoadingMap;` and `- (void)mapViewDidFinishLoadingMap;` so that you can create a mapview, set yourself up as the delegate, call a "loadTiles" method and keep your user entertained on the main thread knowing that the map view will show tiles once the "loadTiles" method fetches what it needs from mapbox servers.

If you are interested in proceeding with this I'd be happy to apply necessary polish and update this PR - just let me know.

example usage:

````
#import "Mapbox.h"
#import "RBMainBoxMapViewController.h"

@interface RBMainBoxMapViewController ()

@property (nonatomic, strong) RMMapView *niceMapView;

@end

@implementation RBMainBoxMapViewController

- (void)viewDidLoad {
[super viewDidLoad];

// create a mapview that does all initialization possible (without tile source) and returns immediately
self.niceMapView = [[RMMapView alloc] initWithFrame:self.view.bounds mapID:@"boundsj.barrachoinchicago" backgroundImage:nil];
// immediately add subview
[self.view addSubview:self.niceMapView];

// become the delegate for this map view
self.niceMapView.delegate = self;

// turn off user interaction since there are no tiles available (yet)
self.niceMapView.userInteractionEnabled = NO;

// kick off asynchronous load of tiles (inits MB tile source and downloads tile json)
// since we are the delegate, we will hear back about the progress of this load attempt via
// delegate callbacks
[self.niceMapView loadTilesWithCenterCoordinate:CLLocationCoordinate2DMake(41.8419, -87.6805) zoomLevel:11.0 maxZoomLevel:14.0 minZoomLevel:10.0];
}

#pragma mark -

// since we are now async, we can do smart UX things like show a spinner...
- (void)mapViewWillStartLoadingMap {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}

// and turn it off
- (void)mapViewDidFinishLoadingMap {
self.niceMapView.userInteractionEnabled = YES;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

}

@end
````