summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSExpression+MGLAdditions.mm
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-09 16:18:57 -0600
committerMinh Nguyễn <mxn@1ec5.org>2017-02-09 14:18:57 -0800
commita1a639120d7662cb68f0ba5770e4f42cc9415069 (patch)
treefc92f9c1f0422da0bda7d35a0a6e446626c5b06d /platform/darwin/src/NSExpression+MGLAdditions.mm
parent272dc3f6a91ee1f0734c6642d610366f4396ec93 (diff)
downloadqtlocation-mapboxgl-a1a639120d7662cb68f0ba5770e4f42cc9415069.tar.gz
[core] Introduce dedicated filter types for $type and $id special cases (#7971)
* [core] Introduce dedicated filter types for $type and $id special cases * [ios, macos] Special-case $id, $type in predicates Also support $id ≟ nil.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm61
1 files changed, 61 insertions, 0 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index f19a41327a..c54102b8c9 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -63,6 +63,67 @@
return {};
}
+- (std::vector<mbgl::FeatureType>)mgl_aggregateFeatureType {
+ if ([self.constantValue isKindOfClass:[NSArray class]] || [self.constantValue isKindOfClass:[NSSet class]]) {
+ std::vector<mbgl::FeatureType> convertedValues;
+ for (id value in self.constantValue) {
+ NSExpression *expression = value;
+ if (![expression isKindOfClass:[NSExpression class]]) {
+ expression = [NSExpression expressionForConstantValue:expression];
+ }
+ convertedValues.push_back(expression.mgl_featureType);
+ }
+ return convertedValues;
+ }
+ [NSException raise:NSInvalidArgumentException
+ format:@"Constant value expression must contain an array or set."];
+ return {};
+}
+
+- (mbgl::FeatureType)mgl_featureType {
+ id value = self.constantValue;
+ if ([value isKindOfClass:NSString.class]) {
+ if ([value isEqualToString:@"Point"]) {
+ return mbgl::FeatureType::Point;
+ }
+ if ([value isEqualToString:@"LineString"]) {
+ return mbgl::FeatureType::LineString;
+ }
+ if ([value isEqualToString:@"Polygon"]) {
+ return mbgl::FeatureType::Polygon;
+ }
+ } else if ([value isKindOfClass:NSNumber.class]) {
+ switch ([value integerValue]) {
+ case 1:
+ return mbgl::FeatureType::Point;
+ case 2:
+ return mbgl::FeatureType::LineString;
+ case 3:
+ return mbgl::FeatureType::Polygon;
+ default:
+ break;
+ }
+ }
+ return mbgl::FeatureType::Unknown;
+}
+
+- (std::vector<mbgl::FeatureIdentifier>)mgl_aggregateFeatureIdentifier {
+ if ([self.constantValue isKindOfClass:[NSArray class]] || [self.constantValue isKindOfClass:[NSSet class]]) {
+ std::vector<mbgl::FeatureIdentifier> convertedValues;
+ for (id value in self.constantValue) {
+ NSExpression *expression = value;
+ if (![expression isKindOfClass:[NSExpression class]]) {
+ expression = [NSExpression expressionForConstantValue:expression];
+ }
+ convertedValues.push_back(expression.mgl_featureIdentifier);
+ }
+ return convertedValues;
+ }
+ [NSException raise:NSInvalidArgumentException
+ format:@"Constant value expression must contain an array or set."];
+ return {};
+}
+
- (mbgl::FeatureIdentifier)mgl_featureIdentifier {
mbgl::Value mbglValue = self.mgl_constantMBGLValue;