[ios, osx] Split MGLDirectionFormatter in two
Split MGLDirectionFormatter into MGLClockDirectionFormatter, which specializes in clock positions, and MGLCompassDirectionFormatter, which boxes the compass. This neatly avoids any confusion that might arise if the developer fails to read the documentation and thinks the original unified formatter can convert between the two types of directions.
This commit is contained in:
committed by
Minh Nguyễn
parent
e5c6cfde4b
commit
2a1a5f0885
52
platform/darwin/include/MGLClockDirectionFormatter.h
Normal file
52
platform/darwin/include/MGLClockDirectionFormatter.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
#import "MGLTypes.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
The `MGLClockDirectionFormatter` class provides properly formatted descriptions
|
||||
of headings relative to the user, known as <i>clock positions</i>. For
|
||||
example, a value of `90` may be formatted as “3 o’clock”, depending on the
|
||||
locale.
|
||||
|
||||
Use this class to create localized heading strings when displaying directions
|
||||
relative to the user’s current location and heading. To format a direction
|
||||
irrespective of the user’s orientation, use `MGLCompassDirectionFormatter`
|
||||
instead.
|
||||
*/
|
||||
@interface MGLClockDirectionFormatter : NSFormatter
|
||||
|
||||
/**
|
||||
The unit style used by this formatter.
|
||||
|
||||
This property defaults to `NSFormattingUnitStyleMedium`.
|
||||
*/
|
||||
@property (nonatomic) NSFormattingUnitStyle unitStyle;
|
||||
|
||||
/**
|
||||
The locale of the receiver.
|
||||
|
||||
The locale determines the output language and numeral system of the output.
|
||||
*/
|
||||
@property (copy) NSLocale *locale;
|
||||
|
||||
/**
|
||||
Returns a clock position string for the provided value.
|
||||
|
||||
@param direction The heading, measured in degrees, where 0° means “straight
|
||||
ahead” and 90° means “directly to your right”.
|
||||
@return The clock position string appropriately formatted for the receiver’s
|
||||
locale.
|
||||
*/
|
||||
- (NSString *)stringFromDirection:(CLLocationDirection)direction;
|
||||
|
||||
/**
|
||||
This method is not supported for the `MGLDirectionFormatter` class.
|
||||
*/
|
||||
- (BOOL)getObjectValue:(out id __nullable * __nullable)obj forString:(NSString *)string errorDescription:(out NSString * __nullable * __nullable)error;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
42
platform/darwin/include/MGLCompassDirectionFormatter.h
Normal file
42
platform/darwin/include/MGLCompassDirectionFormatter.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
#import "MGLTypes.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
The `MGLCompassDirectionFormatter` class provides properly formatted
|
||||
descriptions of absolute headings. For example, a value of `90` may be
|
||||
formatted as “east”, depending on the locale.
|
||||
|
||||
Use this class to create localized heading strings when displaying directions
|
||||
irrespective of the user’s current location. To format a direction relative to
|
||||
the user’s current location, use `MGLCompassDirectionFormatter` instead.
|
||||
*/
|
||||
@interface MGLCompassDirectionFormatter : NSFormatter
|
||||
|
||||
/**
|
||||
The unit style used by this formatter.
|
||||
|
||||
This property defaults to `NSFormattingUnitStyleMedium`.
|
||||
*/
|
||||
@property (nonatomic) NSFormattingUnitStyle unitStyle;
|
||||
|
||||
/**
|
||||
Returns a heading string for the provided value.
|
||||
|
||||
@param direction The heading, measured in degrees, where 0° means “due north”
|
||||
and 90° means “due east”.
|
||||
@return The heading string appropriately formatted for the formatter’s locale.
|
||||
*/
|
||||
- (NSString *)stringFromDirection:(CLLocationDirection)direction;
|
||||
|
||||
/**
|
||||
This method is not supported for the `MGLDirectionFormatter` class.
|
||||
*/
|
||||
- (BOOL)getObjectValue:(out id __nullable * __nullable)obj forString:(NSString *)string errorDescription:(out NSString * __nullable * __nullable)error;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,77 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
#import "MGLTypes.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
The reference point for an `MGLDirectionFormatter`.
|
||||
*/
|
||||
typedef NS_ENUM(NSUInteger, MGLDirectionFormatterOrigin) {
|
||||
/**
|
||||
Directions are assumed to be relative to true north and are given as
|
||||
compass directions, such as “south” for a value of `90`.
|
||||
*/
|
||||
MGLDirectionFormatterOriginNorth = 0,
|
||||
/**
|
||||
Directions are assumed to be relative to the direction in which the user is
|
||||
facing and are given as “clock directions”, such as “6 o’clock” for a value
|
||||
of `90`.
|
||||
*/
|
||||
MGLDirectionFormatterOriginStraightAhead,
|
||||
};
|
||||
|
||||
/**
|
||||
The `MGLDirectionFormatter` class provides properly formatted descriptions of
|
||||
absolute or relative headings. Use this class to create localized heading
|
||||
strings when displaying directional information to users.
|
||||
*/
|
||||
@interface MGLDirectionFormatter : NSFormatter
|
||||
|
||||
/**
|
||||
The receiver’s reference point. The receiver’s input is assumed to be relative
|
||||
to this reference point, and its output is given in the conventional form for
|
||||
directions with this reference point.
|
||||
|
||||
This class does not convert between different reference points. To convert an
|
||||
`CLLocationDirection` with respect to true north into a `CLLocationDirection`
|
||||
with respect to the direction in which the user is currently facing, use Core
|
||||
Location to determine the user’s current heading.
|
||||
|
||||
The default value of this property is `MGLDirectionFormatterOriginNorth`, which
|
||||
means a value of `0` is formatted as “north” in the receiver’s locale.
|
||||
*/
|
||||
@property (nonatomic) MGLDirectionFormatterOrigin origin;
|
||||
|
||||
/**
|
||||
The unit style used by this formatter.
|
||||
|
||||
This property defaults to `NSFormattingUnitStyleMedium`.
|
||||
*/
|
||||
@property (nonatomic) NSFormattingUnitStyle unitStyle;
|
||||
|
||||
/**
|
||||
The locale of the receiver.
|
||||
|
||||
The locale determines the output language as well as the numeral system used
|
||||
when the `relativeToUser` property is set to `YES`.
|
||||
*/
|
||||
@property (copy) NSLocale *locale;
|
||||
|
||||
/**
|
||||
Returns a heading string for the provided value.
|
||||
|
||||
@param direction The heading, measured in degrees.
|
||||
@return The heading string appropriately formatted for the formatter’s locale.
|
||||
*/
|
||||
- (NSString *)stringFromDirection:(CLLocationDirection)direction;
|
||||
|
||||
/**
|
||||
This method is not supported for the `MGLDirectionFormatter` class.
|
||||
*/
|
||||
- (BOOL)getObjectValue:(out id __nullable * __nullable)obj forString:(NSString *)string errorDescription:(out NSString * __nullable * __nullable)error;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Reference in New Issue
Block a user