summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-21 22:07:03 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-22 11:13:02 -0700
commita852ee24fbf6c883b7f64bad9883937eb7b8d80d (patch)
treecee2f80a7ca11160f04a24d1d705de15b7fc0388
parent34a2f142e0bdaf488443dc34185f791eba0e94b9 (diff)
downloadqtlocation-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.
-rw-r--r--platform/darwin/include/MGLGeometry.h49
-rw-r--r--platform/darwin/src/MGLGeometry.mm35
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj6
3 files changed, 87 insertions, 3 deletions
diff --git a/platform/darwin/include/MGLGeometry.h b/platform/darwin/include/MGLGeometry.h
index 8231eed442..1c1bf65efb 100644
--- a/platform/darwin/include/MGLGeometry.h
+++ b/platform/darwin/include/MGLGeometry.h
@@ -95,4 +95,53 @@ NS_INLINE CLLocationDegrees MGLDegreesFromRadians(CGFloat radians) {
return radians * 180 / M_PI;
}
+/**
+ Methods for round-tripping Mapbox geometry structure values.
+ */
+@interface NSValue (MGLGeometryAdditions)
+
+/**
+ Creates a new value object containing the specified Core Location geographic
+ coordinate structure.
+
+ @param coordinate The value for the new object.
+ @return A new value object that contains the geographic coordinate information.
+ */
++ (instancetype)valueWithMGLCoordinate:(CLLocationCoordinate2D)coordinate;
+
+/**
+ The Core Location geographic coordinate structure representation of the value.
+ */
+@property (readonly) CLLocationCoordinate2D MGLCoordinateValue;
+
+/**
+ Creates a new value object containing the specified Mapbox coordinate span
+ structure.
+
+ @param span The value for the new object.
+ @return A new value object that contains the coordinate span information.
+ */
++ (instancetype)valueWithMGLCoordinateSpan:(MGLCoordinateSpan)span;
+
+/**
+ The Mapbox coordinate span structure representation of the value.
+ */
+@property (readonly) MGLCoordinateSpan MGLCoordinateSpanValue;
+
+/**
+ Creates a new value object containing the specified Mapbox coordinate bounds
+ structure.
+
+ @param bounds The value for the new object.
+ @return A new value object that contains the coordinate bounds information.
+ */
++ (instancetype)valueWithMGLCoordinateBounds:(MGLCoordinateBounds)bounds;
+
+/**
+ The Mapbox coordinate bounds structure representation of the value.
+ */
+@property (readonly) MGLCoordinateBounds MGLCoordinateBoundsValue;
+
+@end
+
NS_ASSUME_NONNULL_END
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
+
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 776fea3889..9215474947 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -377,7 +377,7 @@
DABCABBB1CB80692000A7C39 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DABCABBF1CB80717000A7C39 /* locations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = locations.cpp; sourceTree = "<group>"; };
DABCABC01CB80717000A7C39 /* locations.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = locations.hpp; sourceTree = "<group>"; };
- DAC07C961CBB2CD6000CB309 /* mbgl.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = mbgl.xcconfig; path = "../../build/ios/mbgl.xcconfig"; sourceTree = "<group>"; };
+ DAC07C961CBB2CD6000CB309 /* mbgl.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = mbgl.xcconfig; path = ../../build/ios/mbgl.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -1188,7 +1188,7 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
- SYMROOT = "../../build/ios";
+ SYMROOT = ../../build/ios;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@@ -1227,7 +1227,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
- SYMROOT = "../../build/ios";
+ SYMROOT = ../../build/ios;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};