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

Commit

Permalink
refs #935: remove dispatch_once, favor property use, and return immut…
Browse files Browse the repository at this point in the history
…able styles
  • Loading branch information
incanus committed Mar 9, 2015
1 parent 7d06e62 commit 5162f5d
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @interface MGLMapView () <UIGestureRecognizerDelegate, GLKViewDelegate>
@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;
Expand All @@ -92,9 +93,9 @@ - (id)rawStyle;

@end

@implementation MGLMapView {
NSMutableArray *_bundledStyleNames;
}
@implementation MGLMapView

@synthesize bundledStyleNames=_bundledStyleNames;

#pragma mark - Setup & Teardown -

Expand Down Expand Up @@ -940,27 +941,24 @@ - (void)setRawStyle:(NSDictionary *)style

- (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]]]];
}
if (!_bundledStyleNames) {
NSString *stylesPath = [[MGLMapView resourceBundlePath] stringByAppendingString:@"/styles"];

_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];
}
});
[_bundledStyleNames addObjectsFromArray:hybridStyleNames];
}

return _bundledStyleNames;
return [NSArray arrayWithArray:_bundledStyleNames];
}

- (void)useBundledStyleNamed:(NSString *)styleName
Expand Down

0 comments on commit 5162f5d

Please sign in to comment.