Alias hybrid to satellite
Looks terrible at the moment, but the API is closer to what developers would expect. Fixes #935.
This commit is contained in:
committed by
John Firebaugh
parent
a5998dc59b
commit
78900c6eee
@@ -12,7 +12,8 @@ static NSArray *const kStyleNames = @[
|
||||
@"Bright",
|
||||
@"Basic",
|
||||
@"Outdoors",
|
||||
@"Satellite"
|
||||
@"Satellite",
|
||||
@"Hybrid",
|
||||
];
|
||||
|
||||
static NSString *const kStyleVersion = @"v7";
|
||||
|
||||
@@ -92,7 +92,9 @@ NSTimeInterval const MGLAnimationDuration = 0.3;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MGLMapView
|
||||
@implementation MGLMapView {
|
||||
NSMutableArray *_bundledStyleNames;
|
||||
}
|
||||
|
||||
#pragma mark - Setup & Teardown -
|
||||
|
||||
@@ -938,16 +940,40 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
|
||||
|
||||
- (NSArray *)bundledStyleNames
|
||||
{
|
||||
NSString *stylesPath = [[MGLMapView resourceBundlePath] stringByAppendingString:@"/styles"];
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
if (!_bundledStyleNames) {
|
||||
NSString *stylesPath = [[MGLMapView resourceBundlePath] stringByAppendingString:@"/styles"];
|
||||
|
||||
_bundledStyleNames = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:stylesPath error:nil] mutableCopy];
|
||||
|
||||
// Add hybrids
|
||||
NSString *hybridStylePrefix = @"hybrid-";
|
||||
NSString *satelliteStylePrefix = @"satellite-";
|
||||
NSMutableArray *hybridStyleNames = [NSMutableArray array];
|
||||
for (NSString *styleName in _bundledStyleNames) {
|
||||
if ([styleName hasPrefix:satelliteStylePrefix]) {
|
||||
[hybridStyleNames addObject:[hybridStylePrefix stringByAppendingString:[styleName substringFromIndex:[satelliteStylePrefix length]]]];
|
||||
}
|
||||
}
|
||||
[_bundledStyleNames addObjectsFromArray:hybridStyleNames];
|
||||
}
|
||||
});
|
||||
|
||||
NSArray *styleNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:stylesPath error:nil];
|
||||
|
||||
return styleNames;
|
||||
return _bundledStyleNames;
|
||||
}
|
||||
|
||||
- (void)useBundledStyleNamed:(NSString *)styleName
|
||||
{
|
||||
NSString *hybridStylePrefix = @"hybrid-";
|
||||
BOOL isHybrid = [styleName hasPrefix:hybridStylePrefix];
|
||||
if (isHybrid) {
|
||||
styleName = [@"satellite-" stringByAppendingString:[styleName substringFromIndex:[hybridStylePrefix length]]];
|
||||
}
|
||||
[self setStyleURL:[NSString stringWithFormat:@"styles/%@.json", styleName]];
|
||||
if (isHybrid) {
|
||||
[self setAppliedStyleClasses:@[@"contours", @"labels"]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)getStyleOrderedLayerNames
|
||||
|
||||
Reference in New Issue
Block a user