MKTileOverlay with Retina-Tiles

I have problems loading 512x512 pixels in MKMapKit. The server provides 512x512.jpeg tiles.

I could not find a solution or pattern for custom retinal elements in MKMapView.

What am I doing:

When I load them into MKMapView using

overlay = [[MKTileOverlay alloc] initWithURLTemplate:template]; overlay.tileSize = CGSizeMake(512.0f, 512.0f); [_mapView insertOverlay:overlay atIndex:MAP_OVERLAY_INDEX_TILE level:MKOverlayLevelAboveLabels]; 

... the tiles are correct, but only half of them are loaded (not only visually - I sniffed the requests, and the fragments disappeared)

with

  overlay = [[MKTileOverlay alloc] initWithURLTemplate:template]; overlay.tileSize = CGSizeMake(256.0f, 256.0f); [_mapView insertOverlay:overlay atIndex:MAP_OVERLAY_INDEX_TILE level:MKOverlayLevelAboveLabels]; 

... all tiles are displayed, but scaling is incorrect

This is my drawing method:

 (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay { MKOverlayRenderer *overlayRenderer = nil; if([overlay isKindOfClass:MKTileOverlay.class]) { overlayRenderer = [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay]; } return overlayRenderer; } 

... overlayRenderer.contentScaleFactor is always 1 ... no matter what tileSize (iOS simulator 7.1 retina)

Any suggestions?

Best regards, Steve

+6
source share
1 answer

The following code only works on iOS 7 (not iOS 8). Override MKTileOverlayRenderer. The tile size is set to 256.

 @implementation FKDTileOverlayRenderer -(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { CGFloat scale = [[UIScreen mainScreen] scale]; if (scale > 1.0) { CGSize tileSize = ((MKTileOverlay*)self.overlay).tileSize; CGRect rect = [self rectForMapRect:mapRect]; CGContextSaveGState(context); CGAffineTransform t = CGContextGetCTM(context); CGContextConcatCTM(context, CGAffineTransformInvert(t)); double ratio = tileSize.width/(rect.size.width*2); CGContextTranslateCTM(context, (double)(-rect.origin.x)*ratio, tileSize.height+ratio*(double)rect.origin.y); CGContextScaleCTM(context, ratio, -ratio); [super drawMapRect:mapRect zoomScale:zoomScale inContext:context]; CGContextRestoreGState(context); } else [super drawMapRect:mapRect zoomScale:zoomScale inContext:context]; } @end 

In your map view controller:

 - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay { if ([overlay isKindOfClass:[MKTileOverlay class]]) { return [[FKDTileOverlayRenderer alloc] initWithTileOverlay:overlay]; } return nil; } 
+1
source

All Articles