[ios, osx] Geometry value methods
Added category methods on NSValue for converting to and from the structure types defined in MGLGeometry.h. Fixes #4485.
This commit is contained in:
committed by
Minh Nguyễn
parent
34a2f142e0
commit
a852ee24fb
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user