Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With what incanus said with <code>MKTileOverlay</code>, it is like this in the view controller:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSString *tileTemplate = @"http://tile.stamen.com/watercolor/{z}/{x}/{y}.jpg"; MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:tileTemplate]; overlay.canReplaceMapContent = YES; [self.mapView addOverlay:overlay]; [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(37.54827, -121.98857)]; self.mapView.delegate = self; } -(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id&lt;MKOverlay&gt;)overlay { MKTileOverlayRenderer *renderer = [[MKTileOverlayRenderer alloc] initWithOverlay:overlay]; return renderer; } </code></pre> <p>If you need control over how the overlay feeds the data, you need to subclass <code>MKTileOverlay</code> and override <code>loadTileAtPath:result:</code></p> <pre><code>-(void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *, NSError *))result { NSData *tile = [self someHowGetTileImageIntoNSDataBaseOnPath:path]; if (tile) { result(tile, nil); } else { result(nil, [NSError errorWithDomain: CUSTOM_ERROR_DOMAIN code: 1 userInfo:nil]); } } </code></pre> <p>The <code>MKOverlay</code> protocol requires <code>boundingMapRect:</code>, which should returns MKMapRect for the rectangular region that this overlay covers. However, I personally found that if I override it myself, it voids the prior <code>canReplaceMapContent = YES</code> setting as Apple probably does not like to show a blank gray map. So I just let MKTileMapOverlay handles it instead.</p> <p>If your overlay is not actually tiles, then MKTileOverlay does not really apply. But I think you probably can fake it but always reporting nil data within <code>loadTileAtPath:result:</code>, and add your real overlay via another overlay. Another option would be just cover the whole world with <a href="https://stackoverflow.com/questions/8679499/showing-specific-region-using-mapkit/8683569#8683569">black polygon overlay</a>, but then the unsuspecting user would possibly be unknowingly streaming more data than he/she likes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload