如果为iOS MKMapView提供256x256像素的栅格源,它将加载同一区域的四个缩放级别为+1的平铺。因此,看起来磁贴似乎处于高dpi模式。太棒了!
现在,我有一个应用程序,它使用第三方来源的栅格瓷砖。问题是数据看起来低得可怕-dpi。
有没有办法告诉Mapbox,它应该加载给定源的每个瓦片的下一个缩放级别,并使用它?
因此,它应该加载1/0/0.jpg,1/1/0.jpg,1/0/1.jpg和1/1/1.jpg,并将它们用于缩放级别0,而不是加载整个世界的瓦片0/0/0.jpg。因此,基本上不是只有一张256x256的图像,而是有四张这样的图像,512x512的图像看起来更清晰。
问题是..。有没有办法不仅对iOS这样做,而且在对源代码的描述中也这样做?所以它也适用于Web和Android吗?
发布于 2019-08-27 21:55:57
发布于 2020-05-21 07:30:32
为什么不直接放大你的瓦片覆盖子类中的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;
}https://stackoverflow.com/questions/57660976
复制相似问题