From a4c5b4f4b579d321bf3efdeb1ab9fd74075993a8 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Tue, 8 Aug 2017 19:21:58 -0400 Subject: =?UTF-8?q?[ios,=20macos]=20Adapt=20Mapbox=20Streets=E2=80=93sourc?= =?UTF-8?q?ed=20layers=20for=20Dynamic=20Type.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/darwin/src/MGLStyle.mm | 26 ++++++++++++++++++++++++++ platform/darwin/src/MGLStyle_Private.h | 3 +++ platform/ios/src/MGLMapView.mm | 7 +++++++ 3 files changed, 36 insertions(+) diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 1e0a2e02b7..8c72c19e42 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -743,6 +743,32 @@ static NSURL *MGLStyleURL_emerald; self.localizedLayersByIdentifier = [NSMutableDictionary dictionary]; } + [self setPreferredContentSize:nil]; +} + +- (void)setPreferredContentSize:(UIContentSizeCategory)preferredContentSize +{ + for (MGLSymbolStyleLayer *layer in self.layers) { + if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { + continue; + } + + MGLVectorSource *source = (MGLVectorSource *)[self sourceWithIdentifier:layer.sourceIdentifier]; + if (![source isKindOfClass:[MGLVectorSource class]] || !source.mapboxStreets) { + continue; + } + + if ([layer.textFontSize isKindOfClass:[MGLConstantStyleValue class]]) { + NSNumber *textFontSize = [(MGLConstantStyleValue *)layer.textFontSize rawValue]; + textFontSize = [NSNumber numberWithFloat:(textFontSize.floatValue * [self sizeForContentSizeCategory:preferredContentSize])]; + layer.textFontSize = [MGLStyleValue valueWithRawValue:textFontSize]; + } + } +} + +- (CGFloat)sizeForContentSizeCategory:(UIContentSizeCategory)preferredContentSize +{ + return 1.3; } @end diff --git a/platform/darwin/src/MGLStyle_Private.h b/platform/darwin/src/MGLStyle_Private.h index 23ce8fbee0..6b96540272 100644 --- a/platform/darwin/src/MGLStyle_Private.h +++ b/platform/darwin/src/MGLStyle_Private.h @@ -1,4 +1,5 @@ #import "MGLStyle.h" +#import #import "MGLStyleLayer.h" #import "MGLFillStyleLayer.h" @@ -21,6 +22,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses transitionDuration:(NSTimeInterval)transitionDuration; +- (void)setPreferredContentSize:(UIContentSizeCategory)preferredContentSize; + @end NS_ASSUME_NONNULL_END diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 715c32186d..5013e5096c 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -563,6 +563,7 @@ public: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeGL:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferredContentSizeChanged:) name:UIContentSizeCategoryDidChangeNotification object:nil]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; // set initial position @@ -2456,6 +2457,12 @@ public: UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, self.accessibilityValue); } +- (void)preferredContentSizeChanged:(NSNotification *)notification { + UIContentSizeCategory preferredContentSize = [notification.userInfo objectForKey:UIContentSizeCategoryNewValueKey]; + [self.style setPreferredContentSize:preferredContentSize]; + +} + #pragma mark - Geography - + (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingCenterCoordinate -- cgit v1.2.1