summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLRendererConfiguration.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLRendererConfiguration.mm')
-rw-r--r--platform/darwin/src/MGLRendererConfiguration.mm49
1 files changed, 43 insertions, 6 deletions
diff --git a/platform/darwin/src/MGLRendererConfiguration.mm b/platform/darwin/src/MGLRendererConfiguration.mm
index b31da674cf..90778ea86d 100644
--- a/platform/darwin/src/MGLRendererConfiguration.mm
+++ b/platform/darwin/src/MGLRendererConfiguration.mm
@@ -1,5 +1,6 @@
#import "MGLRendererConfiguration.h"
#import "MGLOfflineStorage_Private.h"
+#import "MGLFoundation_Private.h"
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
@@ -7,6 +8,12 @@
#import <AppKit/AppKit.h>
#endif
+static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPre4_0";
+
+@interface MGLRendererConfiguration ()
+@property (nonatomic, readwrite) BOOL perSourceCollisions;
+@end
+
@implementation MGLRendererConfiguration
@@ -14,6 +21,42 @@
return [[self alloc] init];
}
+- (instancetype)init {
+ return [self initWithPropertyDictionary:[[NSBundle mainBundle] infoDictionary]];
+}
+
+- (instancetype)initWithPropertyDictionary:(nonnull NSDictionary *)properties {
+ self = [super init];
+
+ if (self) {
+ // Set the collision behaviour. A value set in `NSUserDefaults.standardUserDefaults`
+ // should override anything in the application's info.plist
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ if ([defaults objectForKey:MGLCollisionBehaviorPre4_0Key]) {
+ _perSourceCollisions = [defaults boolForKey:MGLCollisionBehaviorPre4_0Key];
+ }
+ else {
+ id collisionBehaviourValue = properties[MGLCollisionBehaviorPre4_0Key];
+
+ NSNumber *collisionBehaviourNumber = MGL_OBJC_DYNAMIC_CAST(collisionBehaviourValue, NSNumber);
+
+ if (collisionBehaviourNumber) {
+ _perSourceCollisions = collisionBehaviourNumber.boolValue;
+ } else {
+ // Also support NSString to correspond with the behavior of `-[NSUserDefaults boolForKey:]`
+ NSString *collisionBehaviourString = MGL_OBJC_DYNAMIC_CAST(collisionBehaviourValue, NSString);
+
+ if (collisionBehaviourString) {
+ _perSourceCollisions = collisionBehaviourString.boolValue;
+ }
+ }
+ }
+ }
+
+ return self;
+}
+
- (mbgl::DefaultFileSource *)fileSource {
return [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
}
@@ -40,10 +83,4 @@
return fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional<std::string>();
}
-- (BOOL)perSourceCollisions {
- NSNumber *boolWrapper = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"MGLCollisionBehaviorPre4_0"];
-
- return boolWrapper.boolValue;
-}
-
@end