在 Mapbox 中使用低 dpi 栅格切片的下一个缩放级别以具有高分辨率栅格切片



iOSMKMapView,如果您为其提供 256x256 像素的栅格源,将加载同一区域的四个 +1 缩放级别的切片。因此,磁贴似乎处于高 dpi 模式。棒!

现在,我有一个使用第三方栅格切片源的应用程序。问题是数据看起来非常低dpi。

有没有办法告诉 Mapbox 它应该加载给定源的每个磁贴的下一个缩放级别并改用它?

因此,与其为整个世界加载瓷砖0/0/0.jpg,不如加载1/0/0.jpg1/1/0.jpg1/0/1.jpg1/1/1.jpg,并将其用于缩放级别 0。所以基本上不是有一个 256x256 的图像,而是有四个,给它一个 512x512 的图像,看起来更清晰。

问题是...有没有办法不仅在iOS上做到这一点,而且在源的描述中做到这一点?所以它也适用于网络和安卓?

您可以在请求栅格和矢量切片时使用@2x标志从 Mapbox 请求 512X512 切片

您的查询应如下所示。请注意查询字符串之前的@2x

https://api.mapbox.com/v4/mapbox.satellite/1/0/0@2x.png?access_token={access_token}

为什么不放大磁贴叠加子类中的 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;
}

最新更新