From 0a8858f2da4f637fbf8ae7d3f5ffe4640d3e0c80 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Fri, 7 Oct 2016 15:58:51 -0700 Subject: [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. --- platform/darwin/src/MGLPointAnnotation.mm | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 platform/darwin/src/MGLPointAnnotation.mm (limited to 'platform/darwin/src/MGLPointAnnotation.mm') diff --git a/platform/darwin/src/MGLPointAnnotation.mm b/platform/darwin/src/MGLPointAnnotation.mm new file mode 100644 index 0000000000..ce8e4a2355 --- /dev/null +++ b/platform/darwin/src/MGLPointAnnotation.mm @@ -0,0 +1,34 @@ +#import "MGLPointAnnotation.h" + +#import "MGLShape_Private.h" + +#import + + +@implementation MGLPointAnnotation + +@synthesize coordinate; + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; title = %@; subtitle = %@; coordinate = %f, %f>", + NSStringFromClass([self class]), (void *)self, + self.title ? [NSString stringWithFormat:@"\"%@\"", self.title] : self.title, + self.subtitle ? [NSString stringWithFormat:@"\"%@\"", self.subtitle] : self.subtitle, + coordinate.latitude, coordinate.longitude]; +} + +- (NSDictionary *)geoJSONDictionary +{ + return @{@"type": @"Point", + @"coordinates": @[@(self.coordinate.longitude), @(self.coordinate.latitude)]}; +} + +- (mbgl::Feature)featureObject +{ + mbgl::Point point = { self.coordinate.longitude, self.coordinate.latitude }; + return mbgl::Feature {point}; +} + +@end + -- cgit v1.2.1