@@ -39,7 +39,7 @@ MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point) {
3939
4040@implementation CKCluster {
4141@protected
42- NSMutableOrderedSet <id <CKAnnotation >> *_annotations;
42+ NSMutableOrderedSet <id <MKAnnotation >> *_annotations;
4343
4444 MKMapRect _bounds;
4545 BOOL _invalidate_bounds;
@@ -58,14 +58,14 @@ - (instancetype)init{
5858 return self;
5959}
6060
61- - (NSArray <id<CKAnnotation >> *)annotations {
61+ - (NSArray <id<MKAnnotation >> *)annotations {
6262 return _annotations.array ;
6363}
6464
6565- (MKMapRect)bounds {
6666 if (_invalidate_bounds) {
6767 _bounds = MKMapRectNull;
68- for (id <CKAnnotation > annotation in _annotations) {
68+ for (id <MKAnnotation > annotation in _annotations) {
6969 _bounds = MKMapRectByAddingPoint (_bounds, MKMapPointForCoordinate (annotation.coordinate ));
7070 }
7171
@@ -78,39 +78,35 @@ - (NSUInteger)count {
7878 return _annotations.count ;
7979}
8080
81- - (id <CKAnnotation >)firstAnnotation {
81+ - (id <MKAnnotation >)firstAnnotation {
8282 return _annotations.firstObject ;
8383}
8484
85- - (id <CKAnnotation >)lastAnnotation {
85+ - (id <MKAnnotation >)lastAnnotation {
8686 return _annotations.firstObject ;
8787}
8888
89- - (id <CKAnnotation >)annotationAtIndex : (NSUInteger )index {
89+ - (id <MKAnnotation >)annotationAtIndex : (NSUInteger )index {
9090 return _annotations[index];
9191}
9292
93- - (id <CKAnnotation >)objectAtIndexedSubscript : (NSUInteger )index {
93+ - (id <MKAnnotation >)objectAtIndexedSubscript : (NSUInteger )index {
9494 return _annotations[index];
9595}
9696
97- - (void )addAnnotation : (id <CKAnnotation >)annotation {
97+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
9898 [_annotations addObject: annotation];
99- annotation.cluster = self;
100-
10199 _bounds = MKMapRectByAddingPoint (_bounds, MKMapPointForCoordinate (annotation.coordinate ));
102100}
103101
104- - (void )removeAnnotation : (id <CKAnnotation >)annotation {
105- if (annotation. cluster == self) {
102+ - (void )removeAnnotation : (id <MKAnnotation >)annotation {
103+ if ([_annotations containsObject: self ] ) {
106104 [_annotations removeObject: annotation];
107- annotation.cluster = nil ;
108-
109105 _invalidate_bounds = YES ;
110106 }
111107}
112108
113- - (BOOL )containsAnnotation : (id <CKAnnotation >)annotation {
109+ - (BOOL )containsAnnotation : (id <MKAnnotation >)annotation {
114110 return [_annotations containsObject: annotation];
115111}
116112
@@ -174,20 +170,20 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object
174170
175171@implementation CKCentroidCluster
176172
177- - (void )addAnnotation : (id <CKAnnotation >)annotation {
173+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
178174 [super addAnnotation: annotation];
179175 self.coordinate = [self coordinateByAddingAnnotation: annotation];
180176}
181177
182- - (void )removeAnnotation : (id <CKAnnotation >)annotation {
183- if (annotation. cluster == self) {
184- [super removeAnnotation : annotation];
185-
178+ - (void )removeAnnotation : (id <MKAnnotation >)annotation {
179+ if ([_annotations containsObject: self ] ) {
180+ [_annotations removeObject : annotation];
181+ _invalidate_bounds = YES ;
186182 self.coordinate = [self coordinateByRemovingAnnotation: annotation];
187183 }
188184}
189185
190- - (CLLocationCoordinate2D)coordinateByAddingAnnotation : (id <CKAnnotation >)annotation {
186+ - (CLLocationCoordinate2D)coordinateByAddingAnnotation : (id <MKAnnotation >)annotation {
191187 if (self.count < 2 ) {
192188 return annotation.coordinate ;
193189 }
@@ -200,7 +196,7 @@ - (CLLocationCoordinate2D)coordinateByAddingAnnotation:(id<CKAnnotation>)annotat
200196 return CLLocationCoordinate2DMake (latitude / self.count , longitude / self.count );
201197}
202198
203- - (CLLocationCoordinate2D)coordinateByRemovingAnnotation : (id <CKAnnotation >)annotation {
199+ - (CLLocationCoordinate2D)coordinateByRemovingAnnotation : (id <MKAnnotation >)annotation {
204200 if (self.count < 1 ) {
205201 return kCLLocationCoordinate2DInvalid ;
206202 }
@@ -220,10 +216,9 @@ @implementation CKNearestCentroidCluster {
220216 CLLocationCoordinate2D _center;
221217}
222218
223- - (void )addAnnotation : (id <CKAnnotation >)annotation {
224- if (annotation. cluster != self) {
219+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
220+ if (![_annotations containsObject: self ] ) {
225221 [_annotations addObject: annotation];
226- annotation.cluster = self;
227222
228223 _center = [self coordinateByAddingAnnotation: annotation];
229224 self.coordinate = [self coordinateByDistanceSort ];
@@ -232,10 +227,9 @@ - (void)addAnnotation:(id<CKAnnotation>)annotation {
232227 }
233228}
234229
235- - (void )removeAnnotation : (id <CKAnnotation >)annotation {
236- if (annotation. cluster == self) {
230+ - (void )removeAnnotation : (id <MKAnnotation >)annotation {
231+ if ([_annotations containsObject: self ] ) {
237232 [_annotations removeObject: annotation];
238- annotation.cluster = nil ;
239233
240234 _center = [self coordinateByRemovingAnnotation: annotation];
241235 self.coordinate = [self coordinateByDistanceSort ];
@@ -245,7 +239,7 @@ - (void)removeAnnotation:(id<CKAnnotation>)annotation {
245239}
246240
247241- (CLLocationCoordinate2D)coordinateByDistanceSort {
248- [_annotations sortUsingComparator: ^NSComparisonResult (id <CKAnnotation > _Nonnull obj1, id <CKAnnotation > _Nonnull obj2) {
242+ [_annotations sortUsingComparator: ^NSComparisonResult (id <MKAnnotation > _Nonnull obj1, id <MKAnnotation > _Nonnull obj2) {
249243 double d1 = CKDistance (self->_center , obj1.coordinate );
250244 double d2 = CKDistance (self->_center , obj2.coordinate );
251245 if (d1 > d2) return NSOrderedDescending;
@@ -260,30 +254,28 @@ - (CLLocationCoordinate2D)coordinateByDistanceSort {
260254
261255@implementation CKBottomCluster
262256
263- - (void )addAnnotation : (id <CKAnnotation >)annotation {
264- if (annotation. cluster != self) {
257+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
258+ if (![_annotations containsObject: self ] ) {
265259 NSUInteger index = [_annotations indexOfObject: annotation
266260 inSortedRange: NSMakeRange (0 , _annotations.count)
267261 options: NSBinarySearchingInsertionIndex
268- usingComparator: ^NSComparisonResult (id <CKAnnotation > _Nonnull obj1, id <CKAnnotation > _Nonnull obj2) {
262+ usingComparator: ^NSComparisonResult (id <MKAnnotation > _Nonnull obj1, id <MKAnnotation > _Nonnull obj2) {
269263 if (obj1.coordinate .latitude > obj2.coordinate .latitude ) return NSOrderedDescending;
270264 if (obj1.coordinate .latitude < obj2.coordinate .latitude ) return NSOrderedAscending;
271265 return NSOrderedSame;
272266 }];
273267
274268 [_annotations insertObject: annotation atIndex: index];
275- annotation.cluster = self;
276269
277270 self.coordinate = _annotations.firstObject .coordinate ;
278271
279272 _bounds = MKMapRectByAddingPoint (_bounds, MKMapPointForCoordinate (annotation.coordinate ));
280273 }
281274}
282275
283- - (void )removeAnnotation : (id <CKAnnotation >)annotation {
284- if (annotation. cluster == self) {
276+ - (void )removeAnnotation : (id <MKAnnotation >)annotation {
277+ if ([_annotations containsObject: self ] ) {
285278 [_annotations removeObject: annotation];
286- annotation.cluster = nil ;
287279
288280 self.coordinate = _annotations.firstObject .coordinate ;
289281
0 commit comments