summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-11-29 16:30:37 -0800
committerJesse Bounds <jesse@rebounds.net>2016-12-01 08:57:41 -0800
commit7e9457214a0672f4ba21fa48ce5491174633cb68 (patch)
tree61acb014d9f8fad5f5f16824d1fd056fbed0f4c2 /platform/darwin
parentdbb520662d0145a0219e319a67bbe81326c144e3 (diff)
downloadqtlocation-mapboxgl-7e9457214a0672f4ba21fa48ce5491174633cb68.tar.gz
[ios, macos] Add back support for CONTAINS operator
This reverts commit 6877e3efe73fb6e103c2635f1e4b1c1866b17d5c.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm7
-rw-r--r--platform/darwin/test/MGLFilterTests.mm12
2 files changed, 18 insertions, 1 deletions
diff --git a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm
index aa0e456bb1..19c264aa40 100644
--- a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm
+++ b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm
@@ -68,6 +68,12 @@
filter.values = self.rightExpression.mgl_filterValues;
return filter;
}
+ case NSContainsPredicateOperatorType: {
+ auto filter = mbgl::style::InFilter();
+ filter.key = [self.rightExpression.constantValue UTF8String];
+ filter.values = self.leftExpression.mgl_filterValues;
+ return filter;
+ }
case NSBetweenPredicateOperatorType: {
auto filter = mbgl::style::AllFilter();
auto gteFilter = mbgl::style::GreaterThanEqualsFilter();
@@ -85,7 +91,6 @@
case NSBeginsWithPredicateOperatorType:
case NSEndsWithPredicateOperatorType:
case NSCustomSelectorPredicateOperatorType:
- case NSContainsPredicateOperatorType:
[NSException raise:@"Unsupported operator type"
format:@"NSPredicateOperatorType:%lu is not supported.", (unsigned long)self.predicateOperatorType];
}
diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm
index 2bb188575b..b18400f83a 100644
--- a/platform/darwin/test/MGLFilterTests.mm
+++ b/platform/darwin/test/MGLFilterTests.mm
@@ -74,6 +74,18 @@
[self.mapView.style addLayer:layer];
}
+- (void)testContainsPredicate
+{
+ // core does not have a "contains" filter but we can achieve the equivalent by creating an `mbgl::style::InFilter`
+ // and searching the value for the key
+ NSPredicate *expectedPredicate = [NSPredicate predicateWithFormat:@"park IN %@", @[@"park", @"neighbourhood"]];
+ NSPredicate *containsPredicate = [NSPredicate predicateWithFormat:@"%@ CONTAINS %@", @[@"park", @"neighbourhood"], @"park"];
+
+ layer.predicate = containsPredicate;
+ XCTAssertEqualObjects(layer.predicate, expectedPredicate);
+ [self.mapView.style addLayer:layer];
+}
+
- (void)testBetweenPredicate
{
// core does not have a "between" filter but we can achieve the equivalent by creating a set of greater than or equal / less than or equal