summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLPointCollection.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLPointCollection.mm')
-rw-r--r--platform/darwin/src/MGLPointCollection.mm42
1 files changed, 34 insertions, 8 deletions
diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm
index 387a575b2d..acd78b8b33 100644
--- a/platform/darwin/src/MGLPointCollection.mm
+++ b/platform/darwin/src/MGLPointCollection.mm
@@ -1,5 +1,6 @@
#import "MGLPointCollection_Private.h"
#import "MGLGeometry_Private.h"
+#import "NSArray+MGLAdditions.h"
#import <mbgl/util/geojson.hpp>
#import <mbgl/util/geometry.hpp>
@@ -8,12 +9,10 @@ NS_ASSUME_NONNULL_BEGIN
@implementation MGLPointCollection
{
- MGLCoordinateBounds _overlayBounds;
+ mbgl::optional<mbgl::LatLngBounds> _bounds;
std::vector<CLLocationCoordinate2D> _coordinates;
}
-@synthesize overlayBounds = _overlayBounds;
-
+ (instancetype)pointCollectionWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count
{
return [[self alloc] initWithCoordinates:coords count:count];
@@ -25,14 +24,41 @@ NS_ASSUME_NONNULL_BEGIN
if (self)
{
_coordinates = { coords, coords + count };
+ }
+ return self;
+}
+
+- (nullable instancetype)initWithCoder:(NSCoder *)decoder {
+ if (self = [super initWithCoder:decoder]) {
+ NSArray *coordinates = [decoder decodeObjectOfClass:[NSArray class] forKey:@"coordinates"];
+ _coordinates = [coordinates mgl_coordinates];
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder {
+ [super encodeWithCoder:coder];
+ [coder encodeObject:[NSArray mgl_coordinatesFromCoordinates:_coordinates] forKey:@"coordinates"];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) return YES;
+ if (![other isKindOfClass:[MGLPointCollection class]]) return NO;
+
+ MGLPointCollection *otherCollection = (MGLPointCollection *)other;
+ return ([super isEqual:other]
+ && ((![self geoJSONDictionary] && ![otherCollection geoJSONDictionary]) || [[self geoJSONDictionary] isEqualToDictionary:[otherCollection geoJSONDictionary]]));
+}
+
+- (MGLCoordinateBounds)overlayBounds {
+ if (!_bounds) {
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
- for (auto coordinate : _coordinates)
- {
+ for (auto coordinate : _coordinates) {
bounds.extend(mbgl::LatLng(coordinate.latitude, coordinate.longitude));
}
- _overlayBounds = MGLCoordinateBoundsFromLatLngBounds(bounds);
+ _bounds = bounds;
}
- return self;
+ return MGLCoordinateBoundsFromLatLngBounds(*_bounds);
}
- (NSUInteger)pointCount
@@ -65,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)intersectsOverlayBounds:(MGLCoordinateBounds)overlayBounds
{
- return MGLCoordinateBoundsIntersectsCoordinateBounds(_overlayBounds, overlayBounds);
+ return MGLCoordinateBoundsIntersectsCoordinateBounds(self.overlayBounds, overlayBounds);
}
- (mbgl::Geometry<double>)geometryObject