1

如果您向iOSMKMapView提供 256x256 像素的光栅源,iOS 将加载同一区域的四个 +1 缩放级别的图块。因此,瓷砖似乎处于高 dpi 模式。惊人的!

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

有没有办法告诉 Mapbox 它应该加载给定源的每个图块的下一个缩放级别并使用它来代替?

0/0/0.jpg因此,与其为整个世界加载图块,不如为缩放级别 0 加载1/0/0.jpg、和使用这些图块。因此,基本上,它不会有一个 256x256 的图像,而是有四个,给它一个 512x512 的图像,看起来更清晰。1/1/0.jpg1/0/1.jpg1/1/1.jpg

问题是......有没有办法不仅适用于iOS,而且在源描述中?那么它也适用于 Web 和 Android 吗?

4

2 回答 2

0

您可以使用请求中的标志从 Mapbox@2x请求光栅矢量切片的 512X512切片

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

https://api.mapbox.com/v4/mapbox.satellite/1/0/0@2x.png?access_token={access_token}
于 2019-08-27T13:55:57.327 回答
0

为什么不在你的 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;
}
于 2020-05-20T23:30:31.800 回答