Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit e9b24c1

Browse files
committed
Parameterize label strings, accept an array
1 parent 8ce4dce commit e9b24c1

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

platform/ios/app/MBXViewController.m

+29-7
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
448448
[self styleDynamicPointCollection];
449449
break;
450450
case MBXSettingsRuntimeStylingCountryLabels:
451-
[self styleCountryLabelLanguage];
451+
[self styleCountryLabelsLanguage];
452452
break;
453453
default:
454454
NSAssert(NO, @"All runtime styling setting rows should be implemented");
@@ -913,16 +913,38 @@ - (void)styleDynamicPointCollection
913913
[self.mapView.style addLayer:layer];
914914
}
915915

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
917927
{
918928
NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]];
919-
MGLSymbolStyleLayer *countryLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"country-label-lg"];
920929

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;
924936

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+
}
926948
}
927949

928950
- (NSString *)bestLanguageForUser

0 commit comments

Comments
 (0)