blob: 3b89b19bd823993bf81268444df34a4c1fba38f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#import "MGLAnnotationImage_Private.h"
@interface MGLAnnotationImage ()
@property (nonatomic, strong) NSString *reuseIdentifier;
@property (nonatomic, strong, nullable) NSString *styleIconIdentifier;
@property (nonatomic, weak) id<MGLAnnotationImageDelegate> delegate;
@end
@implementation MGLAnnotationImage
+ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier
{
return [[self alloc] initWithImage:image reuseIdentifier:reuseIdentifier];
}
- (instancetype)initWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super init];
if (self)
{
_image = image;
_reuseIdentifier = [reuseIdentifier copy];
_enabled = YES;
}
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 {
return _reuseIdentifier.hash + _enabled + _image.hash;
}
- (void)setImage:(UIImage *)image {
_image = image;
[self.delegate annotationImageNeedsRedisplay:self];
}
@end
|