diff options
Diffstat (limited to 'platform/darwin/src/MGLShapeCollection.mm')
-rw-r--r-- | platform/darwin/src/MGLShapeCollection.mm | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLShapeCollection.mm b/platform/darwin/src/MGLShapeCollection.mm new file mode 100644 index 0000000000..e317a443fe --- /dev/null +++ b/platform/darwin/src/MGLShapeCollection.mm @@ -0,0 +1,48 @@ +#import "MGLShapeCollection.h" + +#import "MGLShape_Private.h" + +#import <mbgl/style/conversion/geojson.hpp> + +@implementation MGLShapeCollection + ++ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes { + return [[self alloc] initWithShapes:shapes]; +} + +- (instancetype)initWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes { + if (self = [super init]) { + NSAssert(shapes.count, @"Cannot create an empty shape collection"); + _shapes = shapes.copy; + } + return self; +} + +- (CLLocationCoordinate2D)coordinate { + return _shapes.firstObject.coordinate; +} + +- (NSDictionary *)geoJSONDictionary { + return @{@"type": @"GeometryCollection", + @"geometries": [self geometryCollection]}; +} + +- (NSArray *)geometryCollection { + NSMutableArray *geometries = [[NSMutableArray alloc] initWithCapacity:self.shapes.count]; + for (id shape in self.shapes) { + NSDictionary *geometry = [shape geoJSONDictionary]; + [geometries addObject:geometry]; + } + return [geometries copy]; +} + +- (mbgl::Geometry<double>)geometryObject { + mapbox::geojson::geometry_collection collection; + collection.reserve(self.shapes.count); + for (MGLShape *shape in self.shapes) { + collection.push_back([shape geometryObject]); + } + return collection; +} + +@end |