summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLShape.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLShape.mm')
-rw-r--r--platform/darwin/src/MGLShape.mm66
1 files changed, 63 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLShape.mm b/platform/darwin/src/MGLShape.mm
index 889ef8b3d7..984235fd97 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,61 @@
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 = _title.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;
}