I'm currently implementing an MKMapView with a custom tile overlay. Unfortunately the tiles I have are displayed rather small on retina displays making the text on them rather hard to read. Is there a way to scale them up without messing with their location on the map?
I've tried the solution in this question using a custom MKTileOverlayRenderer subclass like this:
class CNTileOverlayRenderer: MKTileOverlayRenderer {
override func drawMapRect(mapRect: MKMapRect, zoomScale: MKZoomScale, inContext context: CGContext) {
guard UIScreen.mainScreen().scale > 1.0 else {
super.drawMapRect(mapRect, zoomScale: zoomScale, inContext: context)
return
}
let tileSize = (self.overlay as! MKTileOverlay).tileSize
let rect = self.rectForMapRect(mapRect)
CGContextSaveGState(context)
let t = CGContextGetCTM(context)
CGContextConcatCTM(context, CGAffineTransformInvert(t))
let ratio = tileSize.width / (rect.size.width * 2)
CGContextTranslateCTM(context, (-rect.origin.x) * ratio, tileSize.height + (ratio * rect.origin.y))
CGContextScaleCTM(context, ratio, -ratio)
super.drawMapRect(mapRect, zoomScale: zoomScale, inContext: context)
CGContextRestoreGState(context)
}
}
Unfortunately this seems to be messing up my tiles rather badly. I can't say I have a lot if any experience working with CGContexts and only played with some of the parameters without achieving much of a success.