diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-04-21 22:07:03 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-04-22 11:13:02 -0700 |
commit | a852ee24fbf6c883b7f64bad9883937eb7b8d80d (patch) | |
tree | cee2f80a7ca11160f04a24d1d705de15b7fc0388 /platform/darwin/src/MGLGeometry.mm | |
parent | 34a2f142e0bdaf488443dc34185f791eba0e94b9 (diff) | |
download | qtlocation-mapboxgl-a852ee24fbf6c883b7f64bad9883937eb7b8d80d.tar.gz |
[ios, osx] Geometry value methods
Added category methods on NSValue for converting to and from the structure types defined in MGLGeometry.h.
Fixes #4485.
Diffstat (limited to 'platform/darwin/src/MGLGeometry.mm')
-rw-r--r-- | platform/darwin/src/MGLGeometry.mm | 35 |
1 files changed, 35 insertions, 0 deletions
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 + |