diff options
Diffstat (limited to 'platform/darwin/src/MGLPolyline.mm')
-rw-r--r-- | platform/darwin/src/MGLPolyline.mm | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLPolyline.mm b/platform/darwin/src/MGLPolyline.mm index b81147a3ba..dd2fccf53d 100644 --- a/platform/darwin/src/MGLPolyline.mm +++ b/platform/darwin/src/MGLPolyline.mm @@ -3,6 +3,8 @@ #import "MGLMultiPoint_Private.h" #import "MGLGeometry_Private.h" +#import "MGLPolyline+MGLAdditions.h" + @implementation MGLPolyline @dynamic overlayBounds; @@ -13,17 +15,21 @@ return [[self alloc] initWithCoordinates:coords count:count]; } -- (mbgl::Annotation)annotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate { +- (mbgl::LineString<double>)lineString { NSUInteger count = self.pointCount; CLLocationCoordinate2D *coordinates = self.coordinates; - + mbgl::LineString<double> geometry; geometry.reserve(self.pointCount); for (NSUInteger i = 0; i < count; i++) { geometry.push_back(mbgl::Point<double>(coordinates[i].longitude, coordinates[i].latitude)); } + + return geometry; +} - mbgl::LineAnnotation annotation { geometry }; +- (mbgl::Annotation)annotationObjectWithDelegate:(id <MGLMultiPointDelegate>)delegate { + mbgl::LineAnnotation annotation { [self lineString] }; annotation.opacity = { static_cast<float>([delegate alphaForShapeAnnotation:self]) }; annotation.color = { [delegate strokeColorForShapeAnnotation:self] }; annotation.width = { static_cast<float>([delegate lineWidthForPolylineAnnotation:self]) }; @@ -31,6 +37,15 @@ return annotation; } +- (mbgl::Feature)featureObject { + return mbgl::Feature {[self lineString]}; +} + +- (NSDictionary *)geoJSONDictionary { + return @{@"type": @"LineString", + @"coordinates": self.mgl_coordinates}; +} + @end @interface MGLMultiPolyline () @@ -67,4 +82,22 @@ return MGLLatLngBoundsFromCoordinateBounds(_overlayBounds).intersects(MGLLatLngBoundsFromCoordinateBounds(overlayBounds)); } +- (mbgl::Feature)featureObject { + mbgl::MultiLineString<double> multiLineString; + multiLineString.reserve(self.polylines.count); + for (MGLPolyline *polyline in self.polylines) { + multiLineString.push_back([polyline lineString]); + } + return mbgl::Feature {multiLineString}; +} + +- (NSDictionary *)geoJSONDictionary { + NSMutableArray *coordinates = [NSMutableArray array]; + for (MGLPolylineFeature *feature in self.polylines) { + [coordinates addObject: feature.mgl_coordinates]; + } + return @{@"type": @"MultiLineString", + @"coordinates": coordinates}; +} + @end |