summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSExpression+MGLAdditions.mm
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-10-07 15:58:51 -0700
committerJesse Bounds <jesse@rebounds.net>2016-10-14 14:59:28 -0700
commit0a8858f2da4f637fbf8ae7d3f5ffe4640d3e0c80 (patch)
tree07afe5efdc678ad58e405d728b65710d50928dff /platform/darwin/src/NSExpression+MGLAdditions.mm
parentf558f6bc4a12fc621589c0b0f50d42c18e00453c (diff)
downloadqtlocation-mapboxgl-0a8858f2da4f637fbf8ae7d3f5ffe4640d3e0c80.tar.gz
[ios, macos] Teach features and shapes about GeoJSON and mbgl types
MGLShape subclasses can now return NSDictionaries that represent the shapes' GeoJSON geometries. MGLFeature classes can now return NSDictionaries that represent the features as GeoJSON features. This makes it trivial to serialize iOS and macOS shapes and features into GeoJSON. MGLFeature instances can also return a representation of themselves as an mbgl::Feature. This capability is used in a refactoring of the implementations of MGLGeoJSONSource to more efficiently transform MGLFeatures into mbgl::Features so they can be fed directly into mbgl::GeoJSONSource without having to round trip through NSJSONSerialization. The MGLFeature identifier is converted into the mbgl::identifier type based on the type of the identifier. The MGLFeature attributes are recursively converted into an mbgl::PropertyMap and each value is converted into one of the types that the PropertyMap's Value variant supports.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm26
1 files changed, 26 insertions, 0 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 52a0b9bd88..392a6d7f5b 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -61,4 +61,30 @@
return { };
}
+- (mbgl::FeatureIdentifier)mgl_featureIdentifier
+{
+ id value = self.constantValue;
+ mbgl::Value mbglValue = [self mgl_filterValue];
+
+ if ([value isKindOfClass:NSString.class]) {
+ return mbglValue.get<std::string>();
+ } else if ([value isKindOfClass:NSNumber.class]) {
+ NSNumber *number = (NSNumber *)value;
+ if ((strcmp([number objCType], @encode(char)) == 0) ||
+ (strcmp([number objCType], @encode(BOOL)) == 0)) {
+ return mbglValue.get<bool>();
+ } else if ( strcmp([number objCType], @encode(double)) == 0 ||
+ strcmp([number objCType], @encode(float)) == 0) {
+ return mbglValue.get<double>();
+ } else if ([number compare:@(0)] == NSOrderedDescending ||
+ [number compare:@(0)] == NSOrderedSame) {
+ return mbglValue.get<uint64_t>();
+ } else if ([number compare:@(0)] == NSOrderedAscending) {
+ return mbglValue.get<int64_t>();
+ }
+ }
+
+ return {};
+}
+
@end