Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core, ios, osx] Version default style URL APIs; deprecated Emerald
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1ec5 committed May 3, 2016
1 parent c82b02c commit 9273433
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 92 deletions.
6 changes: 4 additions & 2 deletions include/mbgl/util/default_styles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ struct DefaultStyle {
};

extern const DefaultStyle streets;
extern const DefaultStyle emerald;
extern const DefaultStyle outdoors;
extern const DefaultStyle light;
extern const DefaultStyle dark;
extern const DefaultStyle satellite;
extern const DefaultStyle hybrid;

const DefaultStyle orderedStyles[] = {
streets, emerald, light, dark, satellite, hybrid,
streets, outdoors, light, dark, satellite, hybrid,
};
const size_t numOrderedStyles = sizeof(orderedStyles) / sizeof(DefaultStyle);

static const unsigned currentVersion = 9;

} // end namespace default_styles
} // end namespace util
} // end namespace mbgl
Expand Down
101 changes: 83 additions & 18 deletions platform/darwin/src/MGLStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
35 changes: 26 additions & 9 deletions platform/darwin/src/MGLStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLTilePyramidOfflineRegion.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (instancetype)init {
- (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) {
Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/test/MGLOfflineRegionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ @implementation MGLOfflineRegionTests
- (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.");
}

- (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.");

Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/test/MGLOfflineStorageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ - (void)testAAALoadPacks {
- (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 },
Expand Down
63 changes: 59 additions & 4 deletions platform/darwin/test/MGLStyleTests.mm
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Mapbox welcomes participation and contributions from everyone. Please read [CON

- Applications linking against the SDK static framework no longer need to add `-ObjC` to the Other Linker Flags (`OTHER_LDFLAGS`) build setting. If you previously added this flag solely for this SDK, removing the flag may potentially reduce the overall size of your application. ([#4641](https://github.com/mapbox/mapbox-gl-native/pull/4641))
- Removed the `armv7s` slice from the SDK to reduce its size. iPhone 5 and iPhone 5c automatically use the `armv7` slice instead. ([#4641](https://github.com/mapbox/mapbox-gl-native/pull/4641))
- Existing MGLStyle class methods that return default style URLs have been deprecated in favor of new methods that require an explicit style version parameter. ([#4759](https://github.com/mapbox/mapbox-gl-native/pull/4759))
- Deprecated `+[MGLStyle emeraldStyleURL]` with no replacement method. To use the Emerald style going forward, we recommend that you use the underlying URL. ([#4759](https://github.com/mapbox/mapbox-gl-native/pull/4759))
- Added `+[MGLStyle outdoorsStyleURLWithVersion:]` for the new Outdoors style. ([#4759](https://github.com/mapbox/mapbox-gl-native/pull/4759))
- The user dot now moves smoothly between user location updates while user location tracking is disabled. ([#1582](https://github.com/mapbox/mapbox-gl-native/pull/1582))
- An MGLAnnotation can be relocated by changing its `coordinate` property in a KVO-compliant way. An MGLMultiPoint cannot be relocated. ([#3835](https://github.com/mapbox/mapbox-gl-native/pull/3835))
- Setting the `image` property of an MGLAnnotationImage to `nil` resets it to the default red pin image and reclaims resources that can be used to customize additional annotations. ([#3835](https://github.com/mapbox/mapbox-gl-native/pull/3835))
Expand Down
18 changes: 9 additions & 9 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,19 @@ - (IBAction)cycleStyles:(__unused id)sender
dispatch_once(&onceToken, ^{
styleNames = @[
@"Streets",
@"Emerald",
@"Outdoors",
@"Light",
@"Dark",
@"Satellite",
@"Hybrid",
];
styleURLs = @[
[MGLStyle streetsStyleURL],
[MGLStyle emeraldStyleURL],
[MGLStyle lightStyleURL],
[MGLStyle darkStyleURL],
[MGLStyle satelliteStyleURL],
[MGLStyle hybridStyleURL],
[MGLStyle streetsStyleURLWithVersion:MGLStyleCurrentVersion],
[MGLStyle outdoorsStyleURLWithVersion:MGLStyleCurrentVersion],
[MGLStyle lightStyleURLWithVersion:MGLStyleCurrentVersion],
[MGLStyle darkStyleURLWithVersion:MGLStyleCurrentVersion],
[MGLStyle satelliteStyleURLWithVersion:MGLStyleCurrentVersion],
[MGLStyle hybridStyleURLWithVersion:MGLStyleCurrentVersion],
];
NSAssert(styleNames.count == styleURLs.count, @"Style names and URLs don’t match.");

Expand All @@ -497,10 +497,10 @@ - (IBAction)cycleStyles:(__unused id)sender
unsigned numStyleURLMethods = 0;
for (NSUInteger i = 0; i < numMethods; i++) {
Method method = methods[i];
if (method_getNumberOfArguments(method) == 2 /* _cmd, self */) {
if (method_getNumberOfArguments(method) == 3 /* _cmd, self, version */) {
SEL selector = method_getName(method);
NSString *name = @(sel_getName(selector));
if ([name rangeOfString:@"StyleURL"].location != NSNotFound) {
if ([name hasSuffix:@"StyleURLWithVersion:"]) {
numStyleURLMethods += 1;
}
}
Expand Down
1 change: 1 addition & 0 deletions platform/ios/jazzy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ custom_categories:
- MGLMapView
- MGLMapViewDelegate
- MGLStyle
- MGLStyleCurrentVersion
- MGLUserTrackingMode
- name: Annotations
children:
Expand Down
Loading

0 comments on commit 9273433

Please sign in to comment.