refs #935: remove dispatch_once, favor property use, and return immutable styles

This commit is contained in:
Justin R. Miller
2015-03-09 16:32:30 -07:00
parent 7d06e62363
commit 5162f5d77e

View File

@@ -66,6 +66,7 @@ NSTimeInterval const MGLAnimationDuration = 0.3;
@property (nonatomic) UIPinchGestureRecognizer *pinch;
@property (nonatomic) UIRotationGestureRecognizer *rotate;
@property (nonatomic) UILongPressGestureRecognizer *quickZoom;
@property (nonatomic) NSMutableArray *bundledStyleNames;
@property (nonatomic, readonly) NSDictionary *allowedStyleTypes;
@property (nonatomic) CGPoint centerPoint;
@property (nonatomic) CGFloat scale;
@@ -92,9 +93,9 @@ NSTimeInterval const MGLAnimationDuration = 0.3;
@end
@implementation MGLMapView {
NSMutableArray *_bundledStyleNames;
}
@implementation MGLMapView
@synthesize bundledStyleNames=_bundledStyleNames;
#pragma mark - Setup & Teardown -
@@ -940,27 +941,24 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (NSArray *)bundledStyleNames
{
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];
}
});
if (!_bundledStyleNames) {
NSString *stylesPath = [[MGLMapView resourceBundlePath] stringByAppendingString:@"/styles"];
return _bundledStyleNames;
_bundledStyleNames = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:stylesPath error:nil] mutableCopy];
// Add satellite raster & "hybrid" (satellite raster + vector contours & labels)
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];
}
return [NSArray arrayWithArray:_bundledStyleNames];
}
- (void)useBundledStyleNamed:(NSString *)styleName