diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-08-16 01:17:11 -0700 |
---|---|---|
committer | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-08-16 10:17:11 +0200 |
commit | 1daba5d04b5f6a704a1ee608b64b7bb42101903f (patch) | |
tree | 50f268ad3dfc459f9814ed2a516c8127786a09b3 /platform/darwin/src | |
parent | 6c6ddd9e86d1be7257178ffd123dde5138d6c7b9 (diff) | |
download | qtlocation-mapboxgl-1daba5d04b5f6a704a1ee608b64b7bb42101903f.tar.gz |
[ios, macos] Accept absolute file paths as style URLs (#6026)
It turns out that mbgl::AssetFileSource supports absolute file URLs in addition to relative file URLs. So replace the file: scheme with asset: while percent-escaping as necessary.
Also added amsterdam.geojson to macos.xcodeproj for consistency with ios.xcodeproj.
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/NSURL+MGLAdditions.h | 17 | ||||
-rw-r--r-- | platform/darwin/src/NSURL+MGLAdditions.m | 21 |
2 files changed, 38 insertions, 0 deletions
diff --git a/platform/darwin/src/NSURL+MGLAdditions.h b/platform/darwin/src/NSURL+MGLAdditions.h new file mode 100644 index 0000000000..70fd79f064 --- /dev/null +++ b/platform/darwin/src/NSURL+MGLAdditions.h @@ -0,0 +1,17 @@ +#import <Foundation/Foundation.h> + +#import "MGLTypes.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface NSURL (MGLAdditions) + +/** + Returns the given URL, modified if necessary to use the asset: URL scheme + expected by mbgl for local requests. + */ +- (nullable NSURL *)mgl_URLByStandardizingScheme; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSURL+MGLAdditions.m b/platform/darwin/src/NSURL+MGLAdditions.m new file mode 100644 index 0000000000..11b84ed8fa --- /dev/null +++ b/platform/darwin/src/NSURL+MGLAdditions.m @@ -0,0 +1,21 @@ +#import "NSURL+MGLAdditions.h" + +@implementation NSURL (MGLAdditions) + +- (nullable NSURL *)mgl_URLByStandardizingScheme { + if (!self.scheme) { + // Relative file URL, already escaped (in order to create the NSURL). + // Assume a relative path into the application’s resource folder. + return [NSURL URLWithString:[@"asset://" stringByAppendingString:self.absoluteString]]; + } else if (self.fileURL) { + // Absolute file URL, so construct a new URL using the unescaped path. + NSURLComponents *components = [[NSURLComponents alloc] init]; + components.scheme = @"asset"; + components.host = @""; + components.path = self.path; + return components.URL; + } + return self; +} + +@end |