Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Represent $type as member selector expression in predicates #7298

Closed
1ec5 opened this issue Dec 6, 2016 · 3 comments
Closed

Represent $type as member selector expression in predicates #7298

1ec5 opened this issue Dec 6, 2016 · 3 comments
Labels
archived Archived because of inactivity bug iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling

Comments

@1ec5
Copy link
Contributor

1ec5 commented Dec 6, 2016

MGLVectorStyleLayer.predicate should recognize expressions invoking the isKindOfClass: selector on self and convert them to comparisons involving $type. The MGLVectorStyleLayer.predicate documentation currently defines the special $type attribute as the following:

The type of geometry represented by the feature. A feature’s type is guaranteed to be one of the following strings:

  • Point for point features, corresponding to the MGLPointAnnotation class
  • LineString for polyline features, corresponding to the MGLPolyline class
  • Polygon for polygon features, corresponding to the MGLPolygon class

These four special strings are discoverable only via documentation, and $type can’t occur inside a predicate format string because $ denotes a predicate variable. Adding a string enumeration for these strings could help with discoverability, but I think a more self-consistent approach would be to use isKindOfClass: in conjunction with the classes we’ve already mapped to the vector feature types, since this is how you filter types when filtering NSArrays. What we currently represent as:

[NSPredicate predicateWithFormat:@"%K in { 'LineString', 'Polygon' }", @"$type"]
NSPredicate(format: "%K in { 'LineString', 'Polygon' }", "$type")

turns into:

[NSPredicate predicateWithFormat:@"(self isKindOfClass: %@) OR (self isKindOfClass: %@)", [MGLPolyline class], [MGLPolygon class]]
NSPredicate(format: "(self isKindOfClass: %@) OR (self isKindOfClass: %@)", MGLPolyline.self, MGLPolygon.self)

Under the hood, self is parsed as +[NSExpression expressionForEvaluatedObject] and has an expression type of NSEvaluatedObjectExpressionType. The isKindOfClass: expression is initialized with -[NSComparisonPredicate initWithLeftExpression:rightExpression:customSelector:], and customSelector contains isKindOfClass:.

/ref #6970
/cc @frederoni @incanus @boundsj

@1ec5
Copy link
Contributor Author

1ec5 commented Jan 25, 2017

Per #7552, $type is currently always represented as an integer: 1 for points, 2 for polylines, and 3 for polygons.

@1ec5
Copy link
Contributor Author

1ec5 commented Nov 30, 2017

As part of #8074, the geometry-type operator would be translated into an isKindOfClass: method call.

@stale stale bot added the archived Archived because of inactivity label Nov 2, 2018
@stale
Copy link

stale bot commented Dec 4, 2018

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Dec 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived Archived because of inactivity bug iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling
Projects
None yet
Development

No branches or pull requests

1 participant