From a852ee24fbf6c883b7f64bad9883937eb7b8d80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 21 Apr 2016 22:07:03 -0700 Subject: [ios, osx] Geometry value methods Added category methods on NSValue for converting to and from the structure types defined in MGLGeometry.h. Fixes #4485. --- platform/darwin/src/MGLGeometry.mm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'platform/darwin/src/MGLGeometry.mm') diff --git a/platform/darwin/src/MGLGeometry.mm b/platform/darwin/src/MGLGeometry.mm index 70f00afd2f..9907f14252 100644 --- a/platform/darwin/src/MGLGeometry.mm +++ b/platform/darwin/src/MGLGeometry.mm @@ -44,3 +44,38 @@ double MGLZoomLevelForAltitude(CLLocationDistance altitude, CGFloat pitch, CLLoc CGFloat mapPixelWidthAtZoom = std::cos(MGLRadiansFromDegrees(latitude)) * mbgl::util::M2PI * mbgl::util::EARTH_RADIUS_M / metersPerPixel; return ::log2(mapPixelWidthAtZoom / mbgl::util::tileSize); } + +@implementation NSValue (MGLGeometryAdditions) + ++ (instancetype)valueWithMGLCoordinate:(CLLocationCoordinate2D)coordinate { + return [self valueWithBytes:&coordinate objCType:@encode(CLLocationCoordinate2D)]; +} + +- (CLLocationCoordinate2D)MGLCoordinateValue { + CLLocationCoordinate2D coordinate; + [self getValue:&coordinate]; + return coordinate; +} + ++ (instancetype)valueWithMGLCoordinateSpan:(MGLCoordinateSpan)span { + return [self valueWithBytes:&span objCType:@encode(MGLCoordinateSpan)]; +} + +- (MGLCoordinateSpan)MGLCoordinateSpanValue { + MGLCoordinateSpan span; + [self getValue:&span]; + return span; +} + ++ (instancetype)valueWithMGLCoordinateBounds:(MGLCoordinateBounds)bounds { + return [self valueWithBytes:&bounds objCType:@encode(MGLCoordinateBounds)]; +} + +- (MGLCoordinateBounds)MGLCoordinateBoundsValue { + MGLCoordinateBounds bounds; + [self getValue:&bounds]; + return bounds; +} + +@end + -- cgit v1.2.1