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

Commit

Permalink
Parameterize label strings, accept an array
Browse files Browse the repository at this point in the history
  • Loading branch information
friedbunny committed Oct 27, 2016
1 parent 8ce4dce commit e9b24c1
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -913,16 +913,38 @@ - (void)styleDynamicPointCollection
[self.mapView.style addLayer:layer];
}

- (void)styleCountryLabelLanguage
-(void)styleCountryLabelsLanguage
{
NSArray<NSString *> *labelLayers = @[
@"country-label-lg",
@"country-label-md",
@"country-label-sm",
];
[self styleLabelLanguageForLayersNamed:labelLayers];
}

- (void)styleLabelLanguageForLayersNamed:(NSArray<NSString *> *)layers
{
NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]];
MGLSymbolStyleLayer *countryLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"country-label-lg"];

MGLStyleConstantValue<NSString *> *countryLabel = (MGLStyleConstantValue<NSString *> *)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<NSString *> *label = (MGLStyleConstantValue<NSString *> *)layer.textField;

countryLayer.textField = [MGLStyleValue<NSString *> valueWithRawValue:language];
_usingLocaleBasedCountryLabels = ![label.rawValue isEqual:bestLanguageForUser];
NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @"{name}";

layer.textField = [MGLStyleValue<NSString *> 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
Expand Down

0 comments on commit e9b24c1

Please sign in to comment.