summaryrefslogtreecommitdiff
path: root/platform/ios/src
diff options
context:
space:
mode:
authorFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2016-10-03 11:33:38 +0200
committerFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2016-12-22 13:58:45 +0100
commit2c7569b879eb2bc9438a17226b333392052dd2db (patch)
tree1e62ab55e23c7a7be057b437f8b6aecfd21d764a /platform/ios/src
parent916cd6c310ee4b7978efa9010123673f067ca6a9 (diff)
downloadqtlocation-mapboxgl-2c7569b879eb2bc9438a17226b333392052dd2db.tar.gz
[ios, macos] features and annotations now conforms to NSSecureCoding
Diffstat (limited to 'platform/ios/src')
-rw-r--r--platform/ios/src/MGLAnnotationImage.h2
-rw-r--r--platform/ios/src/MGLAnnotationImage.m38
-rw-r--r--platform/ios/src/MGLAnnotationView.h2
-rw-r--r--platform/ios/src/MGLAnnotationView.mm28
-rw-r--r--platform/ios/src/MGLUserLocation.h2
-rw-r--r--platform/ios/src/MGLUserLocation.m38
6 files changed, 107 insertions, 3 deletions
diff --git a/platform/ios/src/MGLAnnotationImage.h b/platform/ios/src/MGLAnnotationImage.h
index a7003d7f91..95bce21f51 100644
--- a/platform/ios/src/MGLAnnotationImage.h
+++ b/platform/ios/src/MGLAnnotationImage.h
@@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
objects and may be recycled later and put into a reuse queue that is maintained
by the map view.
*/
-@interface MGLAnnotationImage : NSObject
+@interface MGLAnnotationImage : NSObject <NSSecureCoding>
#pragma mark Initializing and Preparing the Image Object
diff --git a/platform/ios/src/MGLAnnotationImage.m b/platform/ios/src/MGLAnnotationImage.m
index e1085be98d..c753e9e54e 100644
--- a/platform/ios/src/MGLAnnotationImage.m
+++ b/platform/ios/src/MGLAnnotationImage.m
@@ -30,6 +30,44 @@
return self;
}
++ (BOOL)supportsSecureCoding {
+ return YES;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)decoder {
+ if (self = [super init]) {
+ _image = [decoder decodeObjectOfClass:[UIImage class] forKey:@"image"];
+ _reuseIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"reuseIdentifier"];
+ _enabled = [decoder decodeBoolForKey:@"enabled"];
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder {
+ [coder encodeObject:_image forKey:@"image"];
+ [coder encodeObject:_reuseIdentifier forKey:@"reuseIdentifier"];
+ [coder encodeBool:_enabled forKey:@"enabled"];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) return YES;
+ if (![other isKindOfClass:[MGLAnnotationImage class]]) return NO;
+
+ MGLAnnotationImage *otherAnnotationImage = other;
+
+ return ((!_reuseIdentifier && !otherAnnotationImage.reuseIdentifier) || [_reuseIdentifier isEqualToString:otherAnnotationImage.reuseIdentifier])
+ && _enabled == otherAnnotationImage.enabled
+ && ((!_image && !otherAnnotationImage.image) || [UIImagePNGRepresentation(_image) isEqualToData:UIImagePNGRepresentation(otherAnnotationImage.image)]);
+}
+
+- (NSUInteger)hash {
+ NSUInteger hash;
+ hash += [_reuseIdentifier hash];
+ hash += _enabled;
+ hash += [_image hash];
+ return hash;
+}
+
- (void)setImage:(UIImage *)image {
_image = image;
[self.delegate annotationImageNeedsRedisplay:self];
diff --git a/platform/ios/src/MGLAnnotationView.h b/platform/ios/src/MGLAnnotationView.h
index 634e9ad723..d159976a4c 100644
--- a/platform/ios/src/MGLAnnotationView.h
+++ b/platform/ios/src/MGLAnnotationView.h
@@ -50,7 +50,7 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationViewDragState) {
interactivity such as dragging, you can use an `MGLAnnotationImage` instead to
conserve memory and optimize drawing performance.
*/
-@interface MGLAnnotationView : UIView
+@interface MGLAnnotationView : UIView <NSSecureCoding>
#pragma mark Initializing and Preparing the View
diff --git a/platform/ios/src/MGLAnnotationView.mm b/platform/ios/src/MGLAnnotationView.mm
index 96ed8c733e..d2243bdf23 100644
--- a/platform/ios/src/MGLAnnotationView.mm
+++ b/platform/ios/src/MGLAnnotationView.mm
@@ -33,6 +33,34 @@
return self;
}
++ (BOOL)supportsSecureCoding {
+ return YES;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)decoder {
+ if (self = [super initWithCoder:decoder]) {
+ _reuseIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"reuseIdentifier"];
+ _annotation = [decoder decodeObjectOfClass:[NSObject class] forKey:@"annotation"];
+ _centerOffset = [decoder decodeCGVectorForKey:@"centerOffset"];
+ _scalesWithViewingDistance = [decoder decodeBoolForKey:@"scalesWithViewingDistance"];
+ _selected = [decoder decodeBoolForKey:@"selected"];
+ _enabled = [decoder decodeBoolForKey:@"enabled"];
+ self.draggable = [decoder decodeBoolForKey:@"draggable"];
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder {
+ [super encodeWithCoder:coder];
+ [coder encodeObject:_reuseIdentifier forKey:@"reuseIdentifier"];
+ [coder encodeObject:_annotation forKey:@"annotation"];
+ [coder encodeCGVector:_centerOffset forKey:@"centerOffset"];
+ [coder encodeBool:_scalesWithViewingDistance forKey:@"scalesWithViewingDistance"];
+ [coder encodeBool:_selected forKey:@"selected"];
+ [coder encodeBool:_enabled forKey:@"enabled"];
+ [coder encodeBool:_draggable forKey:@"draggable"];
+}
+
- (void)prepareForReuse
{
// Intentionally left blank. The default implementation of this method does nothing.
diff --git a/platform/ios/src/MGLUserLocation.h b/platform/ios/src/MGLUserLocation.h
index f2243815cf..1a27d31dd4 100644
--- a/platform/ios/src/MGLUserLocation.h
+++ b/platform/ios/src/MGLUserLocation.h
@@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
directly. Instead, you retrieve an existing MGLUserLocation object from the
`userLocation` property of the map view displayed in your application.
*/
-@interface MGLUserLocation : NSObject <MGLAnnotation>
+@interface MGLUserLocation : NSObject <MGLAnnotation, NSSecureCoding>
#pragma mark Determining the User’s Position
diff --git a/platform/ios/src/MGLUserLocation.m b/platform/ios/src/MGLUserLocation.m
index a568ec8be1..97e3f740fc 100644
--- a/platform/ios/src/MGLUserLocation.m
+++ b/platform/ios/src/MGLUserLocation.m
@@ -26,6 +26,44 @@ NS_ASSUME_NONNULL_END
return self;
}
++ (BOOL)supportsSecureCoding {
+ return YES;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)decoder {
+ if (self = [super init]) {
+ _location = [decoder decodeObjectOfClass:[CLLocation class] forKey:@"location"];
+ _title = [decoder decodeObjectOfClass:[NSString class] forKey:@"title"];
+ _subtitle = [decoder decodeObjectOfClass:[NSString class] forKey:@"subtitle"];
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder {
+ [coder encodeObject:_location forKey:@"location"];
+ [coder encodeObject:_title forKey:@"title"];
+ [coder encodeObject:_subtitle forKey:@"subtitle"];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) return YES;
+ if (![other isKindOfClass:[MGLUserLocation class]]) return NO;
+
+ MGLUserLocation *otherUserLocation = other;
+ return ((!self.location && !otherUserLocation.location) || [self.location distanceFromLocation:otherUserLocation.location] == 0)
+ && ((!self.title && !otherUserLocation.title) || [self.title isEqualToString:otherUserLocation.title])
+ && ((!self.subtitle && !otherUserLocation.subtitle) || [self.subtitle isEqualToString:otherUserLocation.subtitle]);
+}
+
+- (NSUInteger)hash {
+ NSUInteger hash = [super hash];
+ hash += [_location hash];
+ hash += [_heading hash];
+ hash += [_title hash];
+ hash += [_subtitle hash];
+ return hash;
+}
+
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key
{
return ! [key isEqualToString:@"location"] && ! [key isEqualToString:@"heading"];