mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.36k stars 1.33k forks source link

Error when MGLOfflineStorageDelegate redirects a resource URL to a local file URL #16427

Closed 1ec5 closed 4 years ago

1ec5 commented 4 years ago

If you implement -[MGLOfflineStorageDelegate offlineStorage:URLForResourceOfKind:] to redirect a resource URL to a local file URL, such as the URL of a resource bundled with the application, the request fails because the URL response doesn’t come over HTTP:

https://github.com/mapbox/mapbox-gl-native/blob/9f8c9c61e87868510ee2951c93044c4995478641/platform/darwin/src/http_file_source.mm#L375-L377

To reproduce this issue, set MGLOfflineStorage.delegate to a class that implements -[MGLOfflineStorageDelegate offlineStorage:URLForResourceOfKind:] like so:

- (NSURL *)offlineStorage:(MGLOfflineStorage *)storage URLForResourceOfKind:(MGLResourceKind)kind withURL:(NSURL *)url {
    if (kind == MGLResourceKindImage && [url.scheme isEqualToString:@"boxmap"]) {
        return [[NSBundle bundleForClass:[self class]] URLForResource:@"glyphs" withExtension:@"png"];
    }
    return url;
}

/cc @mapbox/maps-ios

1ec5 commented 4 years ago

16428 fixes this particular error in a tightly scoped way, which I think is valid. However, I think it’s worth investigating whether local file URLs returned by the delegate should end up going through mbgl::LocalFileSource instead of mbgl::HTTPFileSource, just as they would when loading a style from a file URL.

/cc @mapbox/gl-native