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/MGLMultiPoint.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/MGLMultiPoint.mm')
-rw-r--r-- | platform/darwin/src/MGLMultiPoint.mm | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm index c49e970c6b..3b03b78ca6 100644 --- a/platform/darwin/src/MGLMultiPoint.mm +++ b/platform/darwin/src/MGLMultiPoint.mm @@ -1,10 +1,9 @@ #import "MGLMultiPoint_Private.h" #import "MGLGeometry_Private.h" +#import "MGLShape_Private.h" +#import "NSCoder+MGLAdditions.h" #import "MGLTypes.h" -#include <mbgl/util/geo.hpp> -#include <mbgl/util/optional.hpp> - @implementation MGLMultiPoint { mbgl::optional<mbgl::LatLngBounds> _bounds; @@ -27,6 +26,39 @@ return self; } +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + if (self = [super initWithCoder:decoder]) { + _coordinates = [decoder mgl_decodeLocationCoordinates2DForKey:@"coordinates"]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [super encodeWithCoder:coder]; + [coder mgl_encodeLocationCoordinates2D:_coordinates forKey:@"coordinates"]; +} + +- (BOOL)isEqual:(id)other +{ + if (self == other) return YES; + if (![other isKindOfClass:[MGLMultiPoint class]]) return NO; + + MGLMultiPoint *otherMultipoint = other; + return ([super isEqual:otherMultipoint] + && _coordinates == otherMultipoint->_coordinates); +} + +- (NSUInteger)hash +{ + NSUInteger hash = [super hash]; + for (auto coord : _coordinates) { + hash += @(coord.latitude+coord.longitude).hash; + } + return hash; +} + - (CLLocationCoordinate2D)coordinate { NSAssert([self pointCount] > 0, @"A multipoint must have coordinates"); |