diff options
author | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2017-08-01 16:14:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-01 16:14:41 -0400 |
commit | afd4df9dbcdff08654a09e95fdae236061aaa4bd (patch) | |
tree | 31ee16d763c44f28b8556127ad729fc42a7a1e32 /platform/macos/app/MapDocument.m | |
parent | a523b710aceccc992c5aa193acbcd4bf4c93a62d (diff) | |
download | qtlocation-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/macos/app/MapDocument.m')
-rw-r--r-- | platform/macos/app/MapDocument.m | 49 |
1 files changed, 2 insertions, 47 deletions
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 59844d363e..1d22295f50 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -5,7 +5,7 @@ #import "DroppedPinAnnotation.h" #import "MGLStyle+MBXAdditions.h" -#import "MGLVectorSource+MBXAdditions.h" +#import "MGLVectorSource+MGLAdditions.h" #import <Mapbox/Mapbox.h> @@ -344,52 +344,7 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio } - (void)updateLabels { - MGLStyle *style = self.mapView.style; - NSString *preferredLanguage = _isLocalizingLabels ? [MGLVectorSource preferredMapboxStreetsLanguage] : nil; - NSMutableDictionary *localizedKeysByKeyBySourceIdentifier = [NSMutableDictionary dictionary]; - for (MGLSymbolStyleLayer *layer in style.layers) { - if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { - continue; - } - - MGLVectorSource *source = (MGLVectorSource *)[style sourceWithIdentifier:layer.sourceIdentifier]; - if (![source isKindOfClass:[MGLVectorSource class]] || !source.mapboxStreets) { - continue; - } - - NSDictionary *localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier]; - if (!localizedKeysByKey) { - localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier] = [source localizedKeysByKeyForPreferredLanguage:preferredLanguage]; - } - - NSString *(^stringByLocalizingString)(NSString *) = ^ NSString * (NSString *string) { - NSMutableString *localizedString = string.mutableCopy; - [localizedKeysByKey enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull localizedKey, BOOL * _Nonnull stop) { - NSAssert([key isKindOfClass:[NSString class]], @"key is not a string"); - NSAssert([localizedKey isKindOfClass:[NSString class]], @"localizedKey is not a string"); - [localizedString replaceOccurrencesOfString:[NSString stringWithFormat:@"{%@}", key] - withString:[NSString stringWithFormat:@"{%@}", localizedKey] - options:0 - range:NSMakeRange(0, localizedString.length)]; - }]; - return localizedString; - }; - - if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { - NSString *textField = [(MGLConstantStyleValue<NSString *> *)layer.text rawValue]; - layer.text = [MGLStyleValue<NSString *> valueWithRawValue:stringByLocalizingString(textField)]; - } - 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) { - NSString *textField = stop.rawValue; - stops[zoomLevel] = [MGLStyleValue<NSString *> valueWithRawValue:stringByLocalizingString(textField)]; - }]; - function.stops = stops; - layer.text = function; - } - } + self.mapView.style.localizesLabels = _isLocalizingLabels; } - (void)applyPendingState { |