summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorJason Wray <friedbunny@users.noreply.github.com>2018-12-07 21:46:46 -0500
committerGitHub <noreply@github.com>2018-12-07 21:46:46 -0500
commit7cdbe6664ac27d7734e50ea6659dbcf021f61916 (patch)
tree712838bfb8a68f4c729a0e185a6b1cd8cc6e9d40 /platform/darwin
parent1b0365429de2175688f496db3b0ac5cdb1439fb6 (diff)
downloadqtlocation-mapboxgl-7cdbe6664ac27d7734e50ea6659dbcf021f61916.tar.gz
[ios, macos] Update for streets-v8 data and coalesced name fields in v11 styles
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLVectorTileSource.mm4
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm21
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm13
3 files changed, 25 insertions, 13 deletions
diff --git a/platform/darwin/src/MGLVectorTileSource.mm b/platform/darwin/src/MGLVectorTileSource.mm
index a3241d3bce..f7a6869ade 100644
--- a/platform/darwin/src/MGLVectorTileSource.mm
+++ b/platform/darwin/src/MGLVectorTileSource.mm
@@ -79,7 +79,7 @@
An array of locale codes with dedicated name fields in the Mapbox Streets
source.
- https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview
+ https://www.mapbox.com/vector-tiles/mapbox-streets-v8/
*/
static NSArray * const MGLMapboxStreetsLanguages = @[
@"ar", @"de", @"en", @"es", @"fr", @"ja", @"ko", @"pt", @"ru", @"zh",
@@ -141,7 +141,7 @@ static NSArray * const MGLMapboxStreetsAlternativeLanguages = @[
return NO;
}
NSArray *identifiers = [url.host componentsSeparatedByString:@","];
- return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"];
+ return [identifiers containsObject:@"mapbox.mapbox-streets-v8"] || [identifiers containsObject:@"mapbox.mapbox-streets-v7"];
}
@end
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 04152afffd..527cb64b3d 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1398,12 +1398,16 @@ NSDictionary<NSNumber *, NSExpression *> *MGLLocalizedStopDictionary(NSDictionar
- (NSExpression *)mgl_expressionLocalizedIntoLocale:(nullable NSLocale *)locale {
switch (self.expressionType) {
case NSConstantValueExpressionType: {
- NSDictionary *stops = self.constantValue;
- if ([stops isKindOfClass:[NSDictionary class]]) {
- NSDictionary *localizedStops = MGLLocalizedStopDictionary(stops, locale);
- if (localizedStops != stops) {
+ if ([self.constantValue isKindOfClass:[NSDictionary class]]) {
+ NSDictionary *localizedStops = MGLLocalizedStopDictionary(self.constantValue, locale);
+ if (localizedStops != self.constantValue) {
return [NSExpression expressionForConstantValue:localizedStops];
}
+ } else if ([self.constantValue isKindOfClass:[NSArray class]]) {
+ NSArray *localizedValues = MGLLocalizedCollection(self.constantValue, locale);
+ if (localizedValues != self.constantValue) {
+ return [NSExpression expressionForConstantValue:localizedValues];
+ }
}
return self;
}
@@ -1422,19 +1426,18 @@ NSDictionary<NSNumber *, NSExpression *> *MGLLocalizedStopDictionary(NSDictionar
if ([localizedKeyPath isEqualToString:@"name"]) {
return [NSExpression expressionForKeyPath:localizedKeyPath];
}
- // If the keypath is `name_zh-Hans`, fallback to `name_zh` to `name`
- // The `name_zh-Hans` field was added since Mapbox Streets v7
- // See the documentation of name fields for detail https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview
- // CN tiles might using `name_zh-CN` for Simplified Chinese
+ // If the keypath is `name_zh-Hans`, fallback to `name_zh` to `name`.
+ // CN tiles might using `name_zh-CN` for Simplified Chinese.
if ([localizedKeyPath isEqualToString:@"name_zh-Hans"]) {
return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K})",
localizedKeyPath, @"name_zh-CN", @"name_zh", @"name"];
}
- // Mapbox Streets v8 has `name_zh-Hant`, we should fallback to Simplified Chinese if the filed has no value
+ // Mapbox Streets v8 has `name_zh-Hant`, we should fallback to Simplified Chinese if the field has no value.
if ([localizedKeyPath isEqualToString:@"name_zh-Hant"]) {
return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K, %K})",
localizedKeyPath, @"name_zh-Hans", @"name_zh-CN", @"name_zh", @"name"];
}
+
// Other keypath fallback to `name`
return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", localizedKeyPath, @"name"];
}
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 7c853b56d8..f869275dd3 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -1072,11 +1072,20 @@ using namespace std::string_literals;
}
{
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
- NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K})",
- @"name_zh-Hans", @"name_zh-CN", @"name_zh", @"name"];
+ NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K})", @"name_zh-Hans", @"name_zh-CN", @"name_zh", @"name"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"zh-Hans"]], expected);
}
{
+ NSExpression *original = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
+ NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce:({mgl_coalesce:({name_en, name}), mgl_coalesce:({name_en, name})})"];
+ XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:nil], expected);
+ }
+ {
+ NSExpression *original = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
+ NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce:({mgl_coalesce:({name_ja, name}), mgl_coalesce:({name_ja, name})})"];
+ XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"ja-JP"]], expected);
+ }
+ {
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
NSExpression *expected = [NSExpression expressionForKeyPath:@"name"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"tlh"]], expected);