diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-01-16 11:38:35 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-01-16 11:38:35 -0800 |
commit | 7ef2843e6a62116667be6a2c12de085951fdd5ea (patch) | |
tree | 40eca249e044e2706efd1193d617e6eb8e59d708 /platform/darwin/src/MGLPointCollection.mm | |
parent | 76301b252cbc4bc3ae1fc84322bcbcdbd26cae8a (diff) | |
parent | 13b97dd0cebffe36b187bdb74923910def6bd87b (diff) | |
download | qtlocation-mapboxgl-7ef2843e6a62116667be6a2c12de085951fdd5ea.tar.gz |
Merge branch 'release-ios-v3.4.0' into 1ec5-release-ios-v3.4.0-beta.7
Diffstat (limited to 'platform/darwin/src/MGLPointCollection.mm')
-rw-r--r-- | platform/darwin/src/MGLPointCollection.mm | 42 |
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 |