@@ -448,7 +448,7 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
448
448
[self styleDynamicPointCollection ];
449
449
break ;
450
450
case MBXSettingsRuntimeStylingCountryLabels:
451
- [self styleCountryLabelLanguage ];
451
+ [self styleCountryLabelsLanguage ];
452
452
break ;
453
453
default :
454
454
NSAssert (NO , @" All runtime styling setting rows should be implemented" );
@@ -913,16 +913,38 @@ - (void)styleDynamicPointCollection
913
913
[self .mapView.style addLayer: layer];
914
914
}
915
915
916
- - (void )styleCountryLabelLanguage
916
+ -(void )styleCountryLabelsLanguage
917
+ {
918
+ NSArray <NSString *> *labelLayers = @[
919
+ @" country-label-lg" ,
920
+ @" country-label-md" ,
921
+ @" country-label-sm" ,
922
+ ];
923
+ [self styleLabelLanguageForLayersNamed: labelLayers];
924
+ }
925
+
926
+ - (void )styleLabelLanguageForLayersNamed : (NSArray <NSString *> *)layers
917
927
{
918
928
NSString *bestLanguageForUser = [NSString stringWithFormat: @" {name_%@ }" , [self bestLanguageForUser ]];
919
- MGLSymbolStyleLayer *countryLayer = (MGLSymbolStyleLayer *)[self .mapView.style layerWithIdentifier: @" country-label-lg" ];
920
929
921
- MGLStyleConstantValue<NSString *> *countryLabel = (MGLStyleConstantValue<NSString *> *)countryLayer.textField ;
922
- _usingLocaleBasedCountryLabels = ![countryLabel.rawValue isEqual: bestLanguageForUser];
923
- NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @" {name}" ;
930
+ for (NSString *layerName in layers) {
931
+ MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self .mapView.style layerWithIdentifier: layerName];
932
+
933
+ if ([layer isKindOfClass: [MGLSymbolStyleLayer class ]]) {
934
+ if ([layer.textField isKindOfClass: [MGLStyleConstantValue class ]]) {
935
+ MGLStyleConstantValue<NSString *> *label = (MGLStyleConstantValue<NSString *> *)layer.textField ;
924
936
925
- countryLayer.textField = [MGLStyleValue<NSString *> valueWithRawValue:language];
937
+ _usingLocaleBasedCountryLabels = ![label.rawValue isEqual: bestLanguageForUser];
938
+ NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @" {name}" ;
939
+
940
+ layer.textField = [MGLStyleValue<NSString *> valueWithRawValue:language];
941
+ } else if ([layer.textField isKindOfClass: [MGLStyleFunction class ]]) {
942
+ NSLog (@" %@ has a function-based text field — currently unsupported by this method" , layerName);
943
+ }
944
+ } else {
945
+ NSLog (@" %@ is not a symbol style layer" , layerName);
946
+ }
947
+ }
926
948
}
927
949
928
950
- (NSString *)bestLanguageForUser
0 commit comments