summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-19 21:15:30 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-05-06 10:57:54 -0700
commit2a4eeadb295775236fe1a89b50f9179b790b127a (patch)
tree8efffe60f9a2cff3abad624dc889b37809bb0194 /platform/darwin
parentd28b6f37190dc1c9cbb1e3973f8a4534b507865c (diff)
downloadqtlocation-mapboxgl-2a4eeadb295775236fe1a89b50f9179b790b127a.tar.gz
[core, ios, osx] Version default style URL APIs; deprecated Emerald
Updated default styles from v8 to v9. Deprecated the MGLMapView class methods in favor of new methods that take a version parameter. Deprecated Emerald outright in favor of Outdoors. Replaced usage of the unversioned MGLStyle methods with the corresponding versioned methods and MGLStyleCurrentVersion to ensure consistency. Expanded MGLStyle unit tests to also assert that MGLStyle has the right number of style URL methods and that they’re all public. Linked the OS X SDK unit test bundle to libmbgl-core.a. Removed an unnecessary dependency on osxapp. Replaced Emerald with Outdoors in iosapp and osxapp. Fixes the iOS and OS X side of #4577 and #4702.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLStyle.h101
-rw-r--r--platform/darwin/src/MGLStyle.mm35
-rw-r--r--platform/darwin/src/MGLTilePyramidOfflineRegion.mm2
-rw-r--r--platform/darwin/test/MGLOfflineRegionTests.m4
-rw-r--r--platform/darwin/test/MGLOfflineStorageTests.m2
-rw-r--r--platform/darwin/test/MGLStyleTests.mm63
6 files changed, 172 insertions, 35 deletions
diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h
index e5b2de877c..2a2d61657f 100644
--- a/platform/darwin/src/MGLStyle.h
+++ b/platform/darwin/src/MGLStyle.h
@@ -4,50 +4,115 @@
NS_ASSUME_NONNULL_BEGIN
-/** A collection of convenience methods for creating style URLs of default styles provided by Mapbox. These instances of NSURL are cached. */
+/**
+ A version number identifying the latest released version of the suite of default styles provided by Mapbox. This version number may be passed into one of the “StyleURLWithVersion” class methods of MGLStyle.
+
+ The value of this constant is current as of the date on which this SDK was published. Consult the <a href="https://www.mapbox.com/api-documentation/#styles">Mapbox Styles API documentation</a> for the most up-to-date style versioning information.
+
+ @warning The value of this constant may change in a future release of the SDK. If you use any feature that depends on a specific implementation detail in a default style, you may use the current value of this constant or the underlying style URL, but do not use the constant itself. Such implementation details may change significantly from version to version.
+ */
+static const NSInteger MGLStyleCurrentVersion = 9;
+
+/**
+ A collection of convenience methods for creating style URLs of default styles provided by Mapbox.
+ */
@interface MGLStyle : NSObject
/**
- Returns the Streets style URL.
+ Returns the URL to the current version of the Streets style.
+
+ Mapbox Streets is a complete base map that balances nature, commerce, and infrastructure.
+ */
++ (NSURL *)streetsStyleURL __attribute__((deprecated("Use -streetsStyleURLWithVersion:.")));
+
+/**
+ Returns the URL to the given version of the Streets style.
+
+ Mapbox Streets is a complete base map that balances nature, commerce, and infrastructure.
+
+ @param version The style’s latest released version. The current version is given by `MGLStyleCurrentVersion`.
+ */
++ (NSURL *)streetsStyleURLWithVersion:(NSInteger)version;
+
+/**
+ Returns the URL to the current version of the Emerald style.
+
+ Mapbox Emerald is a versatile style with emphasis on road networks and public transportation.
+ */
++ (NSURL *)emeraldStyleURL __attribute__((deprecated("Use <mapbox://styles/mapbox/emerald-v8>.")));
+
+/**
+ Returns the URL to the given version of the Outdoors style.
+
+ Mapbox Outdoors is a rugged style that emphasizes physical terrain and outdoor activities.
+
+ @param version The style’s latest released version. The current version is given by `MGLStyleCurrentVersion`.
+ */
++ (NSURL *)outdoorsStyleURLWithVersion:(NSInteger)version;
+
+/**
+ Returns the URL to the current version of the Light style.
- Mapbox Streets is a complete base map, perfect for incorporating your own data.
+ Mapbox Light is a subtle, light-colored backdrop for data visualizations.
*/
-+ (NSURL *)streetsStyleURL;
++ (NSURL *)lightStyleURL __attribute__((deprecated("Use -lightStyleURLWithVersion:.")));
/**
- Returns the Emerald style URL.
+ Returns the URL to the given version of the Light style.
+
+ Mapbox Light is a subtle, light-colored backdrop for data visualizations.
- Emerald is a versatile style with emphasis on road networks and public transportation.
+ @param version The style’s latest released version. The current version is given by `MGLStyleCurrentVersion`.
*/
-+ (NSURL *)emeraldStyleURL;
++ (NSURL *)lightStyleURLWithVersion:(NSInteger)version;
/**
- Returns the Light style URL.
+ Returns the URL to the current version of the Dark style.
- Light is a subtle, light-colored backdrop for data visualizations.
+ Mapbox Dark is a subtle, dark-colored backdrop for data visualizations.
*/
-+ (NSURL *)lightStyleURL;
++ (NSURL *)darkStyleURL __attribute__((deprecated("Use -darkStyleURLWithVersion:.")));
/**
- Returns the Dark style URL.
+ Returns the URL to the given version of the Dark style.
+
+ Mapbox Dark is a subtle, dark-colored backdrop for data visualizations.
- Dark is a subtle, dark-colored backdrop for data visualizations.
+ @param version The style’s latest released version. The current version is given by `MGLStyleCurrentVersion`.
*/
-+ (NSURL *)darkStyleURL;
++ (NSURL *)darkStyleURLWithVersion:(NSInteger)version;
/**
- Returns the Satellite style URL.
+ Returns the URL to the current version of the Satellite style.
Mapbox Satellite is a beautiful global satellite and aerial imagery layer.
*/
-+ (NSURL *)satelliteStyleURL;
++ (NSURL *)satelliteStyleURL __attribute__((deprecated("Use -satelliteStyleURLWithVersion:.")));
/**
- Returns the Hybrid style URL.
+ Returns the URL to the given version of the Satellite style.
+
+ Mapbox Satellite is a beautiful global satellite and aerial imagery layer.
+
+ @param version The style’s latest released version. The current version is given by `MGLStyleCurrentVersion`.
+ */
++ (NSURL *)satelliteStyleURLWithVersion:(NSInteger)version;
+
+/**
+ Returns the URL to the current version of the Hybrid style.
+
+ Mapbox Hybrid combines the global satellite and aerial imagery of Mapbox Satellite with unobtrusive labels.
+ */
++ (NSURL *)hybridStyleURL __attribute__((deprecated("Use -hybridStyleURLWithVersion:.")));
+
+/**
+ Returns the URL to the given version of the Hybrid style.
+
+ Mapbox Hybrid combines the global satellite and aerial imagery of Mapbox Satellite with unobtrusive labels.
- Hybrid combines the global satellite and aerial imagery of Mapbox Satellite with unobtrusive labels.
+ @param version The style’s latest released version. The current version is given by `MGLStyleCurrentVersion`.
*/
-+ (NSURL *)hybridStyleURL;
++ (NSURL *)hybridStyleURLWithVersion:(NSInteger)version;
- (instancetype)init NS_UNAVAILABLE;
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index 15a25db9e3..c906337a56 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -4,27 +4,44 @@
@implementation MGLStyle
-// name is lowercase
-#define MGL_DEFINE_STYLE(name) \
+static_assert(mbgl::util::default_styles::currentVersion == MGLStyleCurrentVersion, "mbgl::util::default_styles::currentVersion and MGLStyleCurrentVersion disagree.");
+
+/// @param name The style’s marketing name, written in lower camelCase.
+/// @param fileName The last path component in the style’s URL, excluding the version suffix.
+#define MGL_DEFINE_STYLE(name, fileName) \
static NSURL *MGLStyleURL_##name; \
+ (NSURL *)name##StyleURL { \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
- MGLStyleURL_##name = [NSURL URLWithString:@(mbgl::util::default_styles::name.url)]; \
+ MGLStyleURL_##name = [self name##StyleURLWithVersion:MGLStyleCurrentVersion]; \
}); \
return MGLStyleURL_##name; \
+ } \
+ \
+ + (NSURL *)name##StyleURL##WithVersion:(NSInteger)version { \
+ return [NSURL URLWithString:[@"mapbox://styles/mapbox/" #fileName "-v" stringByAppendingFormat:@"%li", (long)version]]; \
}
-MGL_DEFINE_STYLE(streets)
-MGL_DEFINE_STYLE(emerald)
-MGL_DEFINE_STYLE(light)
-MGL_DEFINE_STYLE(dark)
-MGL_DEFINE_STYLE(satellite)
-MGL_DEFINE_STYLE(hybrid)
+MGL_DEFINE_STYLE(streets, streets)
+MGL_DEFINE_STYLE(outdoors, outdoors)
+MGL_DEFINE_STYLE(light, light)
+MGL_DEFINE_STYLE(dark, dark)
+MGL_DEFINE_STYLE(satellite, satellite)
+MGL_DEFINE_STYLE(hybrid, satellite-hybrid)
// Make sure all the styles listed in mbgl::util::default_styles::orderedStyles
// are defined above and also declared in MGLStyle.h.
static_assert(6 == mbgl::util::default_styles::numOrderedStyles,
"mbgl::util::default_styles::orderedStyles and MGLStyle have different numbers of styles.");
+// Emerald is no longer getting new versions as a default style, so the current version is hard-coded here.
+static NSURL *MGLStyleURL_emerald;
++ (NSURL *)emeraldStyleURL {
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ MGLStyleURL_emerald = [NSURL URLWithString:@"mapbox://styles/mapbox/emerald-v8"];
+ });
+ return MGLStyleURL_emerald;
+}
+
@end
diff --git a/platform/darwin/src/MGLTilePyramidOfflineRegion.mm b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm
index d1151de094..9b33d267df 100644
--- a/platform/darwin/src/MGLTilePyramidOfflineRegion.mm
+++ b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm
@@ -33,7 +33,7 @@
- (instancetype)initWithStyleURL:(NSURL *)styleURL bounds:(MGLCoordinateBounds)bounds fromZoomLevel:(double)minimumZoomLevel toZoomLevel:(double)maximumZoomLevel {
if (self = [super init]) {
if (!styleURL) {
- styleURL = [MGLStyle streetsStyleURL];
+ styleURL = [MGLStyle streetsStyleURLWithVersion:MGLStyleCurrentVersion];
}
if (!styleURL.scheme) {
diff --git a/platform/darwin/test/MGLOfflineRegionTests.m b/platform/darwin/test/MGLOfflineRegionTests.m
index 7164acb39c..a578bf0824 100644
--- a/platform/darwin/test/MGLOfflineRegionTests.m
+++ b/platform/darwin/test/MGLOfflineRegionTests.m
@@ -11,7 +11,7 @@
- (void)testStyleURLs {
MGLCoordinateBounds bounds = MGLCoordinateBoundsMake(kCLLocationCoordinate2DInvalid, kCLLocationCoordinate2DInvalid);
MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:nil bounds:bounds fromZoomLevel:0 toZoomLevel:DBL_MAX];
- XCTAssertEqualObjects(region.styleURL, [MGLStyle streetsStyleURL], @"Streets isn’t the default style.");
+ XCTAssertEqualObjects(region.styleURL, [MGLStyle streetsStyleURLWithVersion:MGLStyleCurrentVersion], @"Streets isn’t the default style.");
NSURL *localURL = [NSURL URLWithString:@"beautiful.style"];
XCTAssertThrowsSpecificNamed([[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:localURL bounds:bounds fromZoomLevel:0 toZoomLevel:DBL_MAX], NSException, @"Invalid style URL", @"No exception raised when initializing region with a local file URL as the style URL.");
@@ -19,7 +19,7 @@
- (void)testEquality {
MGLCoordinateBounds bounds = MGLCoordinateBoundsMake(kCLLocationCoordinate2DInvalid, kCLLocationCoordinate2DInvalid);
- MGLTilePyramidOfflineRegion *original = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:[MGLStyle lightStyleURL] bounds:bounds fromZoomLevel:5 toZoomLevel:10];
+ MGLTilePyramidOfflineRegion *original = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:[MGLStyle lightStyleURLWithVersion:MGLStyleCurrentVersion] bounds:bounds fromZoomLevel:5 toZoomLevel:10];
MGLTilePyramidOfflineRegion *copy = [original copy];
XCTAssertEqualObjects(original, copy, @"Tile pyramid region should be equal to its copy.");
diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.m
index dc09b592bf..41a681b1ca 100644
--- a/platform/darwin/test/MGLOfflineStorageTests.m
+++ b/platform/darwin/test/MGLOfflineStorageTests.m
@@ -27,7 +27,7 @@
- (void)testAddPack {
NSUInteger countOfPacks = [MGLOfflineStorage sharedOfflineStorage].packs.count;
- NSURL *styleURL = [MGLStyle lightStyleURL];
+ NSURL *styleURL = [MGLStyle lightStyleURLWithVersion:8];
/// Somewhere near Grape Grove, Ohio, United States.
MGLCoordinateBounds bounds = {
{ .latitude = 39.70358155855172, .longitude = -83.69506472545841 },
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 0d6b7b5c18..63b49b96f2 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -1,26 +1,81 @@
#import "MGLStyle.h"
+#import "NSBundle+MGLAdditions.h"
+
#import <mbgl/util/default_styles.hpp>
#import <XCTest/XCTest.h>
+#import <objc/runtime.h>
@interface MGLStyleTests : XCTestCase
@end
@implementation MGLStyleTests
-- (void)testStyleURLs {
- // Test that all the default styles have publicly-declared MGLStyle class
- // methods and that the URLs are all well-formed.
+- (void)testUnversionedStyleURLs {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqualObjects([MGLStyle streetsStyleURL].absoluteString, @(mbgl::util::default_styles::streets.url));
- XCTAssertEqualObjects([MGLStyle emeraldStyleURL].absoluteString, @(mbgl::util::default_styles::emerald.url));
+ XCTAssertEqualObjects([MGLStyle emeraldStyleURL].absoluteString, @"mapbox://styles/mapbox/emerald-v8");
XCTAssertEqualObjects([MGLStyle lightStyleURL].absoluteString, @(mbgl::util::default_styles::light.url));
XCTAssertEqualObjects([MGLStyle darkStyleURL].absoluteString, @(mbgl::util::default_styles::dark.url));
XCTAssertEqualObjects([MGLStyle satelliteStyleURL].absoluteString, @(mbgl::util::default_styles::satellite.url));
XCTAssertEqualObjects([MGLStyle hybridStyleURL].absoluteString, @(mbgl::util::default_styles::hybrid.url));
+#pragma clang diagnostic pop
+}
+
+- (void)testVersionedStyleURLs {
+ // Test that all the default styles have publicly-declared MGLStyle class
+ // methods and that the URLs all have the right values.
+ XCTAssertEqualObjects([MGLStyle streetsStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::streets.url));
+ XCTAssertEqualObjects([MGLStyle outdoorsStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::outdoors.url));
+ XCTAssertEqualObjects([MGLStyle lightStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::light.url));
+ XCTAssertEqualObjects([MGLStyle darkStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::dark.url));
+ XCTAssertEqualObjects([MGLStyle satelliteStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::satellite.url));
+ XCTAssertEqualObjects([MGLStyle hybridStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::hybrid.url));
static_assert(6 == mbgl::util::default_styles::numOrderedStyles,
"MGLStyleTests isn’t testing all the styles in mbgl::util::default_styles.");
}
+- (void)testStyleURLComprehensiveness {
+ // Make sure this test is comprehensive.
+ const unsigned numImplicitArgs = 2 /* _cmd, self */;
+ unsigned numMethods = 0;
+ Method *methods = class_copyMethodList(object_getClass([MGLStyle class]), &numMethods);
+ unsigned numVersionedMethods = 0;
+ for (NSUInteger i = 0; i < numMethods; i++) {
+ Method method = methods[i];
+ SEL selector = method_getName(method);
+ NSString *name = @(sel_getName(selector));
+ unsigned numArgs = method_getNumberOfArguments(method);
+ if ([name hasSuffix:@"StyleURL"]) {
+ XCTAssertEqual(numArgs, numImplicitArgs, @"Unversioned style URL method should have no parameters, but it has %u.", numArgs - numImplicitArgs);
+ } else if ([name hasSuffix:@"StyleURLWithVersion:"]) {
+ XCTAssertEqual(numArgs, numImplicitArgs + 1, @"Versioned style URL method should have one parameter, but it has %u.", numArgs - numImplicitArgs);
+ numVersionedMethods++;
+ } else {
+ XCTAssertEqual([name rangeOfString:@"URL"].location, NSNotFound, @"MGLStyle style URL method %@ is malformed.", name);
+ }
+ }
+ XCTAssertEqual(mbgl::util::default_styles::numOrderedStyles, numVersionedMethods,
+ @"There are %lu default styles but MGLStyleTests only provides versioned style URL methods for %u of them.",
+ mbgl::util::default_styles::numOrderedStyles, numVersionedMethods);
+
+ // Test that all the versioned style methods are in the public header.
+ NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL
+ URLByAppendingPathComponent:@"Headers" isDirectory:YES]
+ URLByAppendingPathComponent:@"MGLStyle.h"];
+ NSError *styleHeaderError;
+ NSString *styleHeader = [NSString stringWithContentsOfURL:styleHeaderURL usedEncoding:nil error:&styleHeaderError];
+ XCTAssertNil(styleHeaderError, @"Error getting contents of MGLStyle.h.");
+
+ NSError *versionedMethodError;
+ NSString *versionedMethodExpressionString = @(R"RE(^\+\s*\(NSURL\s*\*\s*\)\s*\w+StyleURLWithVersion\s*:\s*\(\s*NSInteger\s*\)\s*version\s*;)RE");
+ NSRegularExpression *versionedMethodExpression = [NSRegularExpression regularExpressionWithPattern:versionedMethodExpressionString options:NSRegularExpressionAnchorsMatchLines error:&versionedMethodError];
+ XCTAssertNil(versionedMethodError, @"Error compiling regular expression to search for versioned methods.");
+ NSUInteger numVersionedMethodDeclarations = [versionedMethodExpression numberOfMatchesInString:styleHeader options:0 range:NSMakeRange(0, styleHeader.length)];
+ XCTAssertEqual(numVersionedMethodDeclarations, numVersionedMethods);
+}
+
@end