This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
MGLStyleLayer predicates (filters) #6049
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,16 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(prope | |
<% } -%> | ||
@interface MGL<%- camelize(type) %>StyleLayer : MGLBaseStyleLayer <MGLStyleLayer> | ||
|
||
<% if (type !== 'background' && type !== 'raster') { -%> | ||
/** | ||
A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>. | ||
|
||
The predicate's left expression must be a string that identifies a feature | ||
property, or one of the special keys. | ||
*/ | ||
@property (nonatomic, nullable) NSPredicate *predicate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs documentation. |
||
|
||
<% } -%> | ||
<% if (layoutProperties.length) { -%> | ||
#pragma mark - Accessing the Layout Attributes | ||
|
||
|
@@ -53,6 +63,7 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(prope | |
|
||
<% } -%> | ||
<% } -%> | ||
<% if (paintProperties.length) { -%> | ||
#pragma mark - Accessing the Paint Attributes | ||
|
||
<% for (const property of paintProperties) { -%> | ||
|
@@ -68,6 +79,7 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(prope | |
*/ | ||
@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) <%- propertyType(property, false, type) %> <%- camelizeWithLeadingLowercase(property.name) %>; | ||
|
||
<% } -%> | ||
<% } -%> | ||
@end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#import <mbgl/util/geometry.hpp> | ||
|
||
/** | ||
Recursively transforms a C++ type into the corresponding Foundation type. | ||
*/ | ||
class ValueEvaluator { | ||
public: | ||
id operator()(const mbgl::NullValue &) const { | ||
return [NSNull null]; | ||
} | ||
|
||
id operator()(const bool &value) const { | ||
return value ? @YES : @NO; | ||
} | ||
|
||
id operator()(const uint64_t &value) const { | ||
return @(value); | ||
} | ||
|
||
id operator()(const int64_t &value) const { | ||
return @(value); | ||
} | ||
|
||
id operator()(const double &value) const { | ||
return @(value); | ||
} | ||
|
||
id operator()(const std::string &value) const { | ||
return @(value.c_str()); | ||
} | ||
|
||
id operator()(const std::vector<mbgl::Value> &values) const { | ||
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:values.size()]; | ||
for (const auto &v : values) { | ||
[objects addObject:mbgl::Value::visit(v, *this)]; | ||
} | ||
return objects; | ||
} | ||
|
||
id operator()(const std::unordered_map<std::string, mbgl::Value> &items) const { | ||
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:items.size()]; | ||
for (auto &item : items) { | ||
attributes[@(item.first.c_str())] = mbgl::Value::visit(item.second, *this); | ||
} | ||
return attributes; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#include <mbgl/style/filter.hpp> | ||
|
||
@interface NSComparisonPredicate (MGLAdditions) | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#import "NSComparisonPredicate+MGLAdditions.h" | ||
|
||
#import "NSPredicate+MGLAdditions.h" | ||
#import "NSExpression+MGLAdditions.h" | ||
|
||
@implementation NSComparisonPredicate (MGLAdditions) | ||
|
||
- (mbgl::style::Filter)mgl_filter | ||
{ | ||
switch (self.predicateOperatorType) { | ||
case NSEqualToPredicateOperatorType: { | ||
auto filter = mbgl::style::EqualsFilter(); | ||
filter.key = self.leftExpression.keyPath.UTF8String; | ||
filter.value = self.rightExpression.mgl_filterValue; | ||
return filter; | ||
} | ||
case NSNotEqualToPredicateOperatorType: { | ||
auto filter = mbgl::style::NotEqualsFilter(); | ||
filter.key = self.leftExpression.keyPath.UTF8String; | ||
filter.value = self.rightExpression.mgl_filterValue; | ||
return filter; | ||
} | ||
case NSGreaterThanPredicateOperatorType: { | ||
auto filter = mbgl::style::GreaterThanFilter(); | ||
filter.key = self.leftExpression.keyPath.UTF8String; | ||
filter.value = self.rightExpression.mgl_filterValue; | ||
return filter; | ||
} | ||
case NSGreaterThanOrEqualToPredicateOperatorType: { | ||
auto filter = mbgl::style::GreaterThanEqualsFilter(); | ||
filter.key = self.leftExpression.keyPath.UTF8String; | ||
filter.value = self.rightExpression.mgl_filterValue; | ||
return filter; | ||
} | ||
case NSLessThanPredicateOperatorType: { | ||
auto filter = mbgl::style::LessThanFilter(); | ||
filter.key = self.leftExpression.keyPath.UTF8String; | ||
filter.value = self.rightExpression.mgl_filterValue; | ||
return filter; | ||
} | ||
case NSLessThanOrEqualToPredicateOperatorType: { | ||
auto filter = mbgl::style::LessThanEqualsFilter(); | ||
filter.key = self.leftExpression.keyPath.UTF8String; | ||
filter.value = self.rightExpression.mgl_filterValue; | ||
return filter; | ||
} | ||
case NSInPredicateOperatorType: { | ||
auto filter = mbgl::style::InFilter(); | ||
filter.key = self.leftExpression.keyPath.UTF8String; | ||
filter.values = self.rightExpression.mgl_filterValues; | ||
return filter; | ||
} | ||
case NSMatchesPredicateOperatorType: | ||
case NSLikePredicateOperatorType: | ||
case NSBeginsWithPredicateOperatorType: | ||
case NSEndsWithPredicateOperatorType: | ||
case NSCustomSelectorPredicateOperatorType: | ||
case NSContainsPredicateOperatorType: | ||
case NSBetweenPredicateOperatorType: | ||
[NSException raise:@"Unsupported operator type" | ||
format:@"NSPredicateOperatorType:%lu is not supported.", (unsigned long)self.predicateOperatorType]; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#include <mbgl/style/filter.hpp> | ||
|
||
@interface NSCompoundPredicate (MGLAdditions) | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly tail work, but we need to document inline which NSExpression operator types we support, as well as the valid values of
$type
and$id
. Linking to the style specification will suffice for now, but it’s suboptimal because the JavaScript syntax and terminology is very foreign to the NSPredicate-based interface we ended up exposing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I’m seeing now that this documentation was originally inline but was removed in response to #6049 (comment). I meant that we should describe the
$type
and$id
keys but do so in an HTML definition list.