summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSURL+MGLAdditions.m
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-08-16 01:17:11 -0700
committerFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2016-08-16 10:17:11 +0200
commit1daba5d04b5f6a704a1ee608b64b7bb42101903f (patch)
tree50f268ad3dfc459f9814ed2a516c8127786a09b3 /platform/darwin/src/NSURL+MGLAdditions.m
parent6c6ddd9e86d1be7257178ffd123dde5138d6c7b9 (diff)
downloadqtlocation-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/NSURL+MGLAdditions.m')
-rw-r--r--platform/darwin/src/NSURL+MGLAdditions.m21
1 files changed, 21 insertions, 0 deletions
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