aboutsummaryrefslogtreecommitdiffstats
path: root/platform/ios/app/MBXViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/app/MBXViewController.m')
-rw-r--r--platform/ios/app/MBXViewController.m106
1 files changed, 42 insertions, 64 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 29c5c6501..3885947cd 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -118,7 +118,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@property (nonatomic) NSInteger styleIndex;
@property (nonatomic) BOOL debugLoggingEnabled;
@property (nonatomic) BOOL customUserLocationAnnnotationEnabled;
-@property (nonatomic) BOOL usingLocaleBasedCountryLabels;
@property (nonatomic) BOOL reuseQueueStatsEnabled;
@property (nonatomic) BOOL showZoomLevelEnabled;
@@ -126,7 +125,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@interface MGLMapView (MBXViewController)
-@property (nonatomic) BOOL usingLocaleBasedCountryLabels;
@property (nonatomic) NSDictionary *annotationViewReuseQueueByIdentifier;
@end
@@ -134,6 +132,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@implementation MBXViewController
{
BOOL _isTouringWorld;
+ BOOL _isTraditional;
}
#pragma mark - Setup & Teardown
@@ -324,7 +323,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@"Remove Annotations",
]];
break;
- case MBXSettingsRuntimeStyling:
+ case MBXSettingsRuntimeStyling: {
+ NSLocale *locale = [NSLocale localeWithLocaleIdentifier:[NSBundle mainBundle].developmentLocalization];
[settingsTitles addObjectsFromArray:@[
@"Add Building Extrusions",
@"Style Water With Function",
@@ -347,11 +347,12 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@"Style Vector Source",
@"Style Raster Source",
@"Style Image Source",
- [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])],
+ [NSString stringWithFormat:@"Label Countries in %@", [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:_isTraditional ? @"zh-Hans" : @"zh-Hant"]],
@"Add Route Line",
@"Dynamically Style Polygon",
]];
break;
+ }
case MBXSettingsMiscellaneous:
[settingsTitles addObjectsFromArray:@[
[NSString stringWithFormat:@"%@ Reuse Queue Stats", (_reuseQueueStatsEnabled ? @"Hide" :@"Show")],
@@ -591,7 +592,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self styleImageSource];
break;
case MBXSettingsRuntimeStylingCountryLabels:
- [self styleCountryLabelsLanguage];
+ _isTraditional = !_isTraditional;
+ [self updateLabels];
break;
case MBXSettingsRuntimeStylingRouteLine:
[self styleRouteLine];
@@ -1346,16 +1348,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
}
}
--(void)styleCountryLabelsLanguage
-{
- NSArray<NSString *> *labelLayers = @[
- @"country-label-lg",
- @"country-label-md",
- @"country-label-sm",
- ];
- [self styleLabelLanguageForLayersNamed:labelLayers];
-}
-
- (void)styleRouteLine
{
CLLocationCoordinate2D coords[] = {
@@ -1436,55 +1428,44 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addLayer:fillStyleLayer];
}
-- (void)styleLabelLanguageForLayersNamed:(NSArray<NSString *> *)layers
+- (void)updateLabels
{
- _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels;
- NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]];
- NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @"{name}";
-
- for (NSString *layerName in layers) {
- MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:layerName];
-
- if ([layer isKindOfClass:[MGLSymbolStyleLayer class]]) {
- if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) {
- MGLConstantStyleValue *label = (MGLConstantStyleValue<NSString *> *)layer.text;
- if ([label.rawValue hasPrefix:@"{name"]) {
- layer.text = [MGLStyleValue valueWithRawValue:language];
- }
- }
- else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) {
- MGLCameraStyleFunction *function = (MGLCameraStyleFunction<NSString *> *)layer.text;
- NSMutableDictionary *stops = function.stops.mutableCopy;
- [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue<NSString *> *stop, BOOL *done) {
- if ([stop.rawValue hasPrefix:@"{name"]) {
- stops[zoomLevel] = [MGLStyleValue<NSString *> valueWithRawValue:language];
- }
- }];
- function.stops = stops;
- layer.text = function;
- }
- } else {
- NSLog(@"%@ is not a symbol style layer", layerName);
+ for (MGLSymbolStyleLayer *layer in self.mapView.style.layers) {
+ if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) {
+ continue;
}
- }
-}
-
-- (NSString *)bestLanguageForUser
-{
- // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview
- NSArray *supportedLanguages = @[ @"ar", @"en", @"es", @"fr", @"de", @"pt", @"ru", @"zh", @"zh-Hans" ];
- NSArray<NSString *> *preferredLanguages = [NSBundle preferredLocalizationsFromArray:supportedLanguages forPreferences:[NSLocale preferredLanguages]];
- NSString *mostSpecificLanguage;
-
- for (NSString *language in preferredLanguages)
- {
- if (language.length > mostSpecificLanguage.length)
- {
- mostSpecificLanguage = language;
+
+ NSString *(^stringByLocalizingString)(NSString *) = ^ NSString * (NSString *string) {
+ return [[string stringByReplacingOccurrencesOfString:@"{name}" withString:@"{name_zh}"]
+ stringByReplacingOccurrencesOfString:@"{name_en}" withString:@"{name_zh}"];
+ };
+
+ if ([layer.textField isKindOfClass:[MGLStyleConstantValue class]]) {
+ NSString *textField = [(MGLStyleConstantValue<NSString *> *)layer.textField rawValue];
+ layer.textField = [MGLStyleValue<NSString *> valueWithRawValue:stringByLocalizingString(textField)];
+ } else if ([layer.textField isKindOfClass:[MGLStyleFunction class]]) {
+ MGLStyleFunction *function = (MGLStyleFunction<NSString *> *)layer.textField;
+ NSMutableDictionary *stops = function.stops.mutableCopy;
+ [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLStyleConstantValue<NSString *> *stop, BOOL *done) {
+ NSString *textField = stop.rawValue;
+ stops[zoomLevel] = [MGLStyleValue<NSString *> valueWithRawValue:stringByLocalizingString(textField)];
+ }];
+ function.stops = stops;
+ layer.textField = function;
+ }
+
+ if ([layer.textTransform isKindOfClass:[MGLStyleConstantValue class]]) {
+ layer.textTransform = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextTransform:_isTraditional ? MGLTextTransformUppercase : MGLTextTransformLowercase]];
+ } else if ([layer.textTransform isKindOfClass:[MGLStyleFunction class]]) {
+ MGLStyleFunction *function = (MGLStyleFunction<NSValue *> *)layer.textTransform;
+ NSMutableDictionary *stops = function.stops.mutableCopy;
+ [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLStyleConstantValue<NSValue *> *stop, BOOL *done) {
+ stops[zoomLevel] = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextTransform:_isTraditional ? MGLTextTransformUppercase : MGLTextTransformLowercase]];
+ }];
+ function.stops = stops;
+ layer.textTransform = function;
}
}
-
- return mostSpecificLanguage ?: @"en";
}
- (IBAction)startWorldTour
@@ -1896,10 +1877,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style
{
- // Default Mapbox styles use {name_en} as their label language, which means
- // that a device with an English-language locale is already effectively
- // using locale-based country labels.
- _usingLocaleBasedCountryLabels = [[self bestLanguageForUser] isEqualToString:@"en"];
+ [self updateLabels];
}
- (void)mapViewRegionIsChanging:(MGLMapView *)mapView