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/MGLPolygon.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/MGLPolygon.mm')
-rw-r--r-- | platform/darwin/src/MGLPolygon.mm | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLPolygon.mm b/platform/darwin/src/MGLPolygon.mm index 393bd31d0d..565de017cc 100644 --- a/platform/darwin/src/MGLPolygon.mm +++ b/platform/darwin/src/MGLPolygon.mm @@ -28,6 +28,32 @@ return self; } +- (instancetype)initWithCoder:(NSCoder *)decoder { + self = [super initWithCoder:decoder]; + if (self) { + _interiorPolygons = [decoder decodeObjectOfClass:[NSArray class] forKey:@"interiorPolygons"]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [super encodeWithCoder:coder]; + [coder encodeObject:self.interiorPolygons forKey:@"interiorPolygons"]; +} + +- (BOOL)isEqual:(id)other { + if (self == other) return YES; + if (![other isKindOfClass:[MGLPolygon class]]) return NO; + + MGLPolygon *otherPolygon = (MGLPolygon *)other; + return ([super isEqual:otherPolygon] && + [[self geoJSONDictionary] isEqualToDictionary:[otherPolygon geoJSONDictionary]]); +} + +- (NSUInteger)hash { + return [super hash] + [[self geoJSONDictionary] hash]; +} + - (mbgl::LinearRing<double>)ring { NSUInteger count = self.pointCount; CLLocationCoordinate2D *coordinates = self.coordinates; @@ -100,6 +126,35 @@ return self; } +- (instancetype)initWithCoder:(NSCoder *)decoder { + if (self = [super initWithCoder:decoder]) { + _polygons = [decoder decodeObjectOfClass:[NSArray class] forKey:@"polygons"]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [super encodeWithCoder:coder]; + [coder encodeObject:_polygons forKey:@"polygons"]; +} + +- (BOOL)isEqual:(id)other { + if (self == other) return YES; + if (![other isKindOfClass:[MGLMultiPolygon class]]) return NO; + + MGLMultiPolygon *otherMultiPolygon = other; + return [super isEqual:other] + && [self.polygons isEqualToArray:otherMultiPolygon.polygons]; +} + +- (NSUInteger)hash { + NSUInteger hash = [super hash]; + for (MGLPolygon *polygon in self.polygons) { + hash += [polygon hash]; + } + return hash; +} + - (BOOL)intersectsOverlayBounds:(MGLCoordinateBounds)overlayBounds { return MGLCoordinateBoundsIntersectsCoordinateBounds(_overlayBounds, overlayBounds); } |