Skip to content

Instantly share code, notes, and snippets.

@ccabanero
Last active December 26, 2015 20:28
Show Gist options
  • Save ccabanero/7208451 to your computer and use it in GitHub Desktop.
Save ccabanero/7208451 to your computer and use it in GitHub Desktop.
iOS - Adding TileStream cache to MapKit
@interface MapViewController()
@property (nonatomic, weak) IBOutlet MKMapView *mapView;
@property (nonatomic, strong) MKTileOverlay *overlay;
@end
@implementation MapViewController
@synthesize mapView = _mapView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSString *template = @"http://1.2.3.4:8888/v2/bangladesh_districts/{z}/{x}/{y}.png";
self.overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
self.overlay.canReplaceMapContent = YES;
[self.mapView addOverlay:self.overlay level:MKOverlayLevelAboveLabels];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
return [[MKTileOverlayRenderer alloc] initWithOverlay:overlay];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
self.overlay = nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment