Moved mbgl::util::default_styles to a more appropriate location, where iOS platform code can also find it. Moved -[MGLMapView bundledStyleURLs] (which is now deprecated) and the style switcher in iosapp to default_styles. Added a collection of convenience methods for getting style URLs. It makes little sense to layer an enum atop this, as MapKit does, because MGLMapView styles aren’t limited to this set. A good analogy is UIColor. This also makes for a good entry point for future runtime styling APIs. Introduced independent constants for each default style, because it’s more common to need access to a particular style than to iterate over them. This fact is apparent in the MGLStyle class, which now uses macros and assertions to ensure that it’s kept up-to-date with changes in default_styles. /ref #1462
31 lines
920 B
Plaintext
31 lines
920 B
Plaintext
#import "MGLStyle.h"
|
|
|
|
#import <mbgl/util/default_styles.hpp>
|
|
|
|
@implementation MGLStyle
|
|
|
|
// name is lowercase
|
|
#define MGL_DEFINE_STYLE(name) \
|
|
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)]; \
|
|
}); \
|
|
return MGLStyleURL_##name; \
|
|
}
|
|
|
|
MGL_DEFINE_STYLE(streets)
|
|
MGL_DEFINE_STYLE(emerald)
|
|
MGL_DEFINE_STYLE(light)
|
|
MGL_DEFINE_STYLE(dark)
|
|
MGL_DEFINE_STYLE(satellite)
|
|
MGL_DEFINE_STYLE(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.");
|
|
|
|
@end
|