为什么不在你的 tile overlay 子类中放大 256 图像呢?
- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *, NSError *))result {
if (!result) {
return;
}
self.tileSize = CGSizeMake(512, 512);
NSString *URLString = [self.internalTemplate stringByReplacingOccurrencesOfString:@"{x}" withString:[NSString stringWithFormat:@"%li", (long)path.x]];
URLString = [URLString stringByReplacingOccurrencesOfString:@"{y}" withString:[NSString stringWithFormat:@"%li", (long)path.y]];
URLString = [URLString stringByReplacingOccurrencesOfString:@"{z}" withString:[NSString stringWithFormat:@"%li", (long)path.z]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]];
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
}
UIImage *image = [UIImage imageWithData:data];
UIImage *resized = [self imageWithImage:image scaledToSize:CGSizeMake(512, 512)];
result(UIImagePNGRepresentation(resized), error);
}];
[task resume];
}
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 1.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}