diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index a5a63b3717d..79009a0ccfe 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -448,7 +448,7 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath [self styleDynamicPointCollection]; break; case MBXSettingsRuntimeStylingCountryLabels: - [self styleCountryLabelLanguage]; + [self styleCountryLabelsLanguage]; break; default: NSAssert(NO, @"All runtime styling setting rows should be implemented"); @@ -913,16 +913,38 @@ - (void)styleDynamicPointCollection [self.mapView.style addLayer:layer]; } -- (void)styleCountryLabelLanguage +-(void)styleCountryLabelsLanguage +{ + NSArray *labelLayers = @[ + @"country-label-lg", + @"country-label-md", + @"country-label-sm", + ]; + [self styleLabelLanguageForLayersNamed:labelLayers]; +} + +- (void)styleLabelLanguageForLayersNamed:(NSArray *)layers { NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]]; - MGLSymbolStyleLayer *countryLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"country-label-lg"]; - MGLStyleConstantValue *countryLabel = (MGLStyleConstantValue *)countryLayer.textField; - _usingLocaleBasedCountryLabels = ![countryLabel.rawValue isEqual: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.textField isKindOfClass:[MGLStyleConstantValue class]]) { + MGLStyleConstantValue *label = (MGLStyleConstantValue *)layer.textField; - countryLayer.textField = [MGLStyleValue valueWithRawValue:language]; + _usingLocaleBasedCountryLabels = ![label.rawValue isEqual:bestLanguageForUser]; + NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @"{name}"; + + layer.textField = [MGLStyleValue valueWithRawValue:language]; + } else if ([layer.textField isKindOfClass:[MGLStyleFunction class]]) { + NSLog(@"%@ has a function-based text field — currently unsupported by this method", layerName); + } + } else { + NSLog(@"%@ is not a symbol style layer", layerName); + } + } } - (NSString *)bestLanguageForUser