Skip to content
This repository was archived by the owner on May 9, 2018. It is now read-only.

Better async map view pattern - #397

Closed
boundsj wants to merge 4 commits into
mapbox:developfrom
boundsj:develop_nice_async_view
Closed

boundsj wants to merge 4 commits into
mapbox:developfrom
boundsj:develop_nice_async_view

Conversation

@boundsj

@boundsj boundsj commented Feb 21, 2014

Copy link
Copy Markdown

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 - <RMMapViewDelegate>

// 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

@incanus

incanus commented Feb 24, 2014

Copy link
Copy Markdown
Contributor

Appreciate your work here, @boundsj -- just wanted to let you know that I will be checking it out.

@incanus

incanus commented Mar 18, 2014

Copy link
Copy Markdown
Contributor

I really like the cleanliness of this API:

[self.niceMapView loadTilesWithCenterCoordinate:CLLocationCoordinate2DMake(41.8419, -87.6805) zoomLevel:11.0 maxZoomLevel:14.0 minZoomLevel:10.0];

It's basically like "setup the map view, get everything in place, then kickoff the loading of tiles (as well as metadata associated with the map)".

One thing this does however is tie RMMapView and RMTileSource together. I think the tile source model is a strength of this project, though, and future versions will keep the concept of varying sources (raster tiles, vector tiles, data overlays, etc.) and the ability to order them arbitrarily as layers.

As mentioned over in #286 (comment), a lot of work by @wsnook is going into this over in the MBXMapKit project and I'd like to let that settle down before we dive too deep in this project. That project, being based on MapKit, is a lot simpler and allows for a tighter and more Apple-like API, so once we work out something clean there, we can apply that thinking here. I think these projects may be converging in the medium-term anyway.

I'll close this for now, but I am totally game to discuss future changes along these lines @boundsj. Thanks again for the PR.

@incanus incanus closed this Mar 18, 2014
@boundsj

boundsj commented Mar 18, 2014

Copy link
Copy Markdown
Author

Awesome. Thanks @incanus, @wsnook

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants