summaryrefslogtreecommitdiff
path: root/platform/ios/app/MBXViewController.m
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2017-08-01 16:14:41 -0400
committerGitHub <noreply@github.com>2017-08-01 16:14:41 -0400
commitafd4df9dbcdff08654a09e95fdae236061aaa4bd (patch)
tree31ee16d763c44f28b8556127ad729fc42a7a1e32 /platform/ios/app/MBXViewController.m
parenta523b710aceccc992c5aa193acbcd4bf4c93a62d (diff)
downloadqtlocation-mapboxgl-afd4df9dbcdff08654a09e95fdae236061aaa4bd.tar.gz
[ios] adapt Mapbox Streets–sourced layers for user preferred language (#9582)
* [ios] Update label localization * [ios, macos] Move MGLVectorSource+MBXAdditions.h to darwin. * [ios, macos] Adapt Mapbox Streets to the user preferred language. * [ios, macos] Clarify style localization documentation. * [ios, macos] Update localization examples * [ios, macos] Add style language reset to original. * [ios, macos] Update changelogs. * [ios, macos] Rename Vector Source Additions to MGL standard. * [ios, macos] Add suport for stop localization.
Diffstat (limited to 'platform/ios/app/MBXViewController.m')
-rw-r--r--platform/ios/app/MBXViewController.m43
1 files changed, 3 insertions, 40 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index d3927374a7..ebbc218017 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -343,7 +343,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@"Update Shape Source: Features",
@"Style Vector Source",
@"Style Raster Source",
- [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])],
+ [NSString stringWithFormat:@"Show Labels in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])],
@"Add Route Line",
@"Dynamically Style Polygon",
]];
@@ -1274,12 +1274,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
-(void)styleCountryLabelsLanguage
{
- NSArray<NSString *> *labelLayers = @[
- @"country-label-lg",
- @"country-label-md",
- @"country-label-sm",
- ];
- [self styleLabelLanguageForLayersNamed:labelLayers];
+ _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels;
+ self.mapView.style.localizesLabels = _usingLocaleBasedCountryLabels;
}
- (void)styleRouteLine
@@ -1362,39 +1358,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addLayer:fillStyleLayer];
}
-- (void)styleLabelLanguageForLayersNamed:(NSArray<NSString *> *)layers
-{
- _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);
- }
- }
-}
-
- (NSString *)bestLanguageForUser
{
// https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview