diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-10-03 11:33:38 +0200 |
---|---|---|
committer | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-12-22 13:58:45 +0100 |
commit | 2c7569b879eb2bc9438a17226b333392052dd2db (patch) | |
tree | 1e62ab55e23c7a7be057b437f8b6aecfd21d764a /platform/darwin/src/MGLShape.mm | |
parent | 916cd6c310ee4b7978efa9010123673f067ca6a9 (diff) | |
download | qtlocation-mapboxgl-2c7569b879eb2bc9438a17226b333392052dd2db.tar.gz |
[ios, macos] features and annotations now conforms to NSSecureCoding
Diffstat (limited to 'platform/darwin/src/MGLShape.mm')
-rw-r--r-- | platform/darwin/src/MGLShape.mm | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLShape.mm b/platform/darwin/src/MGLShape.mm index 889ef8b3d7..4ddf7c9df7 100644 --- a/platform/darwin/src/MGLShape.mm +++ b/platform/darwin/src/MGLShape.mm @@ -2,6 +2,15 @@ #import "MGLFeature_Private.h" +#import "NSString+MGLAdditions.h" +#import "MGLTypes.h" + +#import <mbgl/util/geo.hpp> + +bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D rhs) { + return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude; +} + @implementation MGLShape + (nullable MGLShape *)shapeWithData:(NSData *)data encoding:(NSStringEncoding)encoding error:(NSError * _Nullable *)outError { @@ -42,10 +51,63 @@ return [string dataUsingEncoding:NSUTF8StringEncoding]; } -- (CLLocationCoordinate2D)coordinate { - [NSException raise:@"MGLAbstractClassException" - format:@"MGLShape is an abstract class"]; ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (instancetype)initWithCoder:(NSCoder *)coder +{ + if (self = [super init]) { + _title = [coder decodeObjectOfClass:[NSString class] forKey:@"title"]; + _subtitle = [coder decodeObjectOfClass:[NSString class] forKey:@"subtitle"]; +#if !TARGET_OS_IPHONE + _toolTip = [coder decodeObjectOfClass:[NSString class] forKey:@"toolTip"]; +#endif + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:_title forKey:@"title"]; + [coder encodeObject:_subtitle forKey:@"subtitle"]; +#if !TARGET_OS_IPHONE + [coder encodeObject:_toolTip forKey:@"toolTip"]; +#endif +} + +- (BOOL)isEqual:(id)other +{ + if (other == self) { return YES; } + id <MGLAnnotation> annotation = other; + +#if TARGET_OS_IPHONE + return ((!_title && ![annotation title]) || [_title isEqualToString:[annotation title]]) + && ((!_subtitle && ![annotation subtitle]) || [_subtitle isEqualToString:[annotation subtitle]]); +#else + return ((!_title && ![annotation title]) || [_title isEqualToString:[annotation title]]) + && ((!_subtitle && ![annotation subtitle]) || [_subtitle isEqualToString:[annotation subtitle]]) + && ((!_toolTip && ![annotation toolTip]) || [_toolTip isEqualToString:[annotation toolTip]]); +#endif +} + +- (NSUInteger)hash +{ + NSUInteger hash; + hash += _title.hash; + hash += _subtitle.hash; +#if !TARGET_OS_IPHONE + hash += _toolTip.hash; +#endif + return hash; +} +- (CLLocationCoordinate2D)coordinate +{ + [[NSException exceptionWithName:@"MGLAbstractClassException" + reason:@"MGLShape is an abstract class" + userInfo:nil] raise]; return kCLLocationCoordinate2DInvalid; } |