blob: e317a443fe302420fee79bee62e55464102c4435 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
|