From b3dbdb389ff712ace00857e3e72894f0bb3afe3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 20 Nov 2015 00:13:44 -0800 Subject: [PATCH] [iOS] Set application root as asset root As of #2746, we no longer bundle any styles with the SDK, so the asset: URL scheme is unused. Instead, point asset: to the application root for developer convenience and consistency with the Android and default asset roots. Also fixed an issue that prevented relative URLs from being treated as asset: URLs. Fixes #1208, fixes #3050. --- CHANGELOG.md | 1 + platform/darwin/asset_root.mm | 13 +------------ platform/ios/MGLMapView.mm | 4 ++-- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b11e9d6d..2a924b42a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Known issues: - The `styleID` property has been removed from MGLMapView. Instead, set the `styleURL` property to an NSURL in the form `mapbox://styles/STYLE_ID`. If you previously set the style ID in Interface Builder’s Attributes inspector, delete the `styleID` entry from the User Defined Runtime Attributes section of the Identity inspector, then set the new “Style URL” inspectable to a value in the form `mapbox://styles/STYLE_ID`. ([#2632](https://github.com/mapbox/mapbox-gl-native/pull/2632)) - Default styles such as Streets are no longer bundled with the SDK; instead, they are loaded at runtime from the style API on mapbox.com. As always, you can use these default styles with any valid access token, and Streets continues to be `MGLMapView`’s initial style. The `bundledStyleURLs` property on `MGLMapView` has been deprecated in favor of several class methods on `MGLStyle` that provide direct access to the default styles. ([#2746](https://github.com/mapbox/mapbox-gl-native/pull/2746)) - The SDK now builds with Bitcode enabled. A version of libMapbox.a with Bitcode disabled is also available. ([#2332](https://github.com/mapbox/mapbox-gl-native/issues/2332), [#3003](https://github.com/mapbox/mapbox-gl-native/pull/3003)) +- The style URL can be set to a local resource: `asset://local-color.json` and `local-color.json` both resolve to a file named `local-color.json` in the application’s root folder. ([#3087](https://github.com/mapbox/mapbox-gl-native/pull/3087)) - The double-tap-drag gesture for zooming in and out is now consistent with the Google Maps SDK. ([#2153](https://github.com/mapbox/mapbox-gl-native/pull/2153)) - A new `MGLAnnotationImage.enabled` property allows you to disable touch events on individual annotations. ([#2501](https://github.com/mapbox/mapbox-gl-native/pull/2501)) - Fixed a rendering issue that caused one-way arrows along tile boundaries to point due east instead of in the direction of travel. ([#2530](https://github.com/mapbox/mapbox-gl-native/pull/2530)) diff --git a/platform/darwin/asset_root.mm b/platform/darwin/asset_root.mm index f47f5d36d..a4a3d13c8 100644 --- a/platform/darwin/asset_root.mm +++ b/platform/darwin/asset_root.mm @@ -2,24 +2,13 @@ #include -@interface MGLApplicationRootBundleCanary : NSObject -@end - -@implementation MGLApplicationRootBundleCanary -@end - namespace mbgl { namespace platform { // Returns the path to the root folder of the application. const std::string &assetRoot() { static const std::string root = []() -> std::string { - NSString *path = [[NSBundle bundleForClass:[MGLApplicationRootBundleCanary class]] pathForResource:@"Mapbox" ofType:@"bundle"]; - if (!path) { - path = [[[NSBundle mainBundle] resourceURL] path]; - } - return {[path cStringUsingEncoding : NSUTF8StringEncoding], - [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding]}; + return [[[[NSBundle mainBundle] resourceURL] path] UTF8String]; }(); return root; } diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index ce7cefa40..b088185f0 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -192,8 +192,8 @@ std::chrono::steady_clock::duration durationInSeconds(float duration) if ( ! [styleURL scheme]) { - // Assume a relative path into the developer’s bundle. - styleURL = [[NSBundle mainBundle] URLForResource:styleURL.path withExtension:nil]; + // Assume a relative path into the application bundle. + styleURL = [NSURL URLWithString:[@"asset://" stringByAppendingString:[styleURL absoluteString]]]; } _mbglMap->setStyleURL([[styleURL absoluteString] UTF8String]);