@@ -39,7 +39,7 @@ MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point) {
39
39
40
40
@implementation CKCluster {
41
41
@protected
42
- NSMutableOrderedSet <id <CKAnnotation >> *_annotations;
42
+ NSMutableOrderedSet <id <MKAnnotation >> *_annotations;
43
43
44
44
MKMapRect _bounds;
45
45
BOOL _invalidate_bounds;
@@ -58,14 +58,14 @@ - (instancetype)init{
58
58
return self;
59
59
}
60
60
61
- - (NSArray <id<CKAnnotation >> *)annotations {
61
+ - (NSArray <id<MKAnnotation >> *)annotations {
62
62
return _annotations.array ;
63
63
}
64
64
65
65
- (MKMapRect)bounds {
66
66
if (_invalidate_bounds) {
67
67
_bounds = MKMapRectNull;
68
- for (id <CKAnnotation > annotation in _annotations) {
68
+ for (id <MKAnnotation > annotation in _annotations) {
69
69
_bounds = MKMapRectByAddingPoint (_bounds, MKMapPointForCoordinate (annotation.coordinate ));
70
70
}
71
71
@@ -78,39 +78,35 @@ - (NSUInteger)count {
78
78
return _annotations.count ;
79
79
}
80
80
81
- - (id <CKAnnotation >)firstAnnotation {
81
+ - (id <MKAnnotation >)firstAnnotation {
82
82
return _annotations.firstObject ;
83
83
}
84
84
85
- - (id <CKAnnotation >)lastAnnotation {
85
+ - (id <MKAnnotation >)lastAnnotation {
86
86
return _annotations.firstObject ;
87
87
}
88
88
89
- - (id <CKAnnotation >)annotationAtIndex : (NSUInteger )index {
89
+ - (id <MKAnnotation >)annotationAtIndex : (NSUInteger )index {
90
90
return _annotations[index];
91
91
}
92
92
93
- - (id <CKAnnotation >)objectAtIndexedSubscript : (NSUInteger )index {
93
+ - (id <MKAnnotation >)objectAtIndexedSubscript : (NSUInteger )index {
94
94
return _annotations[index];
95
95
}
96
96
97
- - (void )addAnnotation : (id <CKAnnotation >)annotation {
97
+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
98
98
[_annotations addObject: annotation];
99
- annotation.cluster = self;
100
-
101
99
_bounds = MKMapRectByAddingPoint (_bounds, MKMapPointForCoordinate (annotation.coordinate ));
102
100
}
103
101
104
- - (void )removeAnnotation : (id <CKAnnotation >)annotation {
105
- if (annotation. cluster == self) {
102
+ - (void )removeAnnotation : (id <MKAnnotation >)annotation {
103
+ if ([_annotations containsObject: self ] ) {
106
104
[_annotations removeObject: annotation];
107
- annotation.cluster = nil ;
108
-
109
105
_invalidate_bounds = YES ;
110
106
}
111
107
}
112
108
113
- - (BOOL )containsAnnotation : (id <CKAnnotation >)annotation {
109
+ - (BOOL )containsAnnotation : (id <MKAnnotation >)annotation {
114
110
return [_annotations containsObject: annotation];
115
111
}
116
112
@@ -174,20 +170,20 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object
174
170
175
171
@implementation CKCentroidCluster
176
172
177
- - (void )addAnnotation : (id <CKAnnotation >)annotation {
173
+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
178
174
[super addAnnotation: annotation];
179
175
self.coordinate = [self coordinateByAddingAnnotation: annotation];
180
176
}
181
177
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 ;
186
182
self.coordinate = [self coordinateByRemovingAnnotation: annotation];
187
183
}
188
184
}
189
185
190
- - (CLLocationCoordinate2D)coordinateByAddingAnnotation : (id <CKAnnotation >)annotation {
186
+ - (CLLocationCoordinate2D)coordinateByAddingAnnotation : (id <MKAnnotation >)annotation {
191
187
if (self.count < 2 ) {
192
188
return annotation.coordinate ;
193
189
}
@@ -200,7 +196,7 @@ - (CLLocationCoordinate2D)coordinateByAddingAnnotation:(id<CKAnnotation>)annotat
200
196
return CLLocationCoordinate2DMake (latitude / self.count , longitude / self.count );
201
197
}
202
198
203
- - (CLLocationCoordinate2D)coordinateByRemovingAnnotation : (id <CKAnnotation >)annotation {
199
+ - (CLLocationCoordinate2D)coordinateByRemovingAnnotation : (id <MKAnnotation >)annotation {
204
200
if (self.count < 1 ) {
205
201
return kCLLocationCoordinate2DInvalid ;
206
202
}
@@ -220,10 +216,9 @@ @implementation CKNearestCentroidCluster {
220
216
CLLocationCoordinate2D _center;
221
217
}
222
218
223
- - (void )addAnnotation : (id <CKAnnotation >)annotation {
224
- if (annotation. cluster != self) {
219
+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
220
+ if (![_annotations containsObject: self ] ) {
225
221
[_annotations addObject: annotation];
226
- annotation.cluster = self;
227
222
228
223
_center = [self coordinateByAddingAnnotation: annotation];
229
224
self.coordinate = [self coordinateByDistanceSort ];
@@ -232,10 +227,9 @@ - (void)addAnnotation:(id<CKAnnotation>)annotation {
232
227
}
233
228
}
234
229
235
- - (void )removeAnnotation : (id <CKAnnotation >)annotation {
236
- if (annotation. cluster == self) {
230
+ - (void )removeAnnotation : (id <MKAnnotation >)annotation {
231
+ if ([_annotations containsObject: self ] ) {
237
232
[_annotations removeObject: annotation];
238
- annotation.cluster = nil ;
239
233
240
234
_center = [self coordinateByRemovingAnnotation: annotation];
241
235
self.coordinate = [self coordinateByDistanceSort ];
@@ -245,7 +239,7 @@ - (void)removeAnnotation:(id<CKAnnotation>)annotation {
245
239
}
246
240
247
241
- (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) {
249
243
double d1 = CKDistance (self->_center , obj1.coordinate );
250
244
double d2 = CKDistance (self->_center , obj2.coordinate );
251
245
if (d1 > d2) return NSOrderedDescending;
@@ -260,30 +254,28 @@ - (CLLocationCoordinate2D)coordinateByDistanceSort {
260
254
261
255
@implementation CKBottomCluster
262
256
263
- - (void )addAnnotation : (id <CKAnnotation >)annotation {
264
- if (annotation. cluster != self) {
257
+ - (void )addAnnotation : (id <MKAnnotation >)annotation {
258
+ if (![_annotations containsObject: self ] ) {
265
259
NSUInteger index = [_annotations indexOfObject: annotation
266
260
inSortedRange: NSMakeRange (0 , _annotations.count)
267
261
options: NSBinarySearchingInsertionIndex
268
- usingComparator: ^NSComparisonResult (id <CKAnnotation > _Nonnull obj1, id <CKAnnotation > _Nonnull obj2) {
262
+ usingComparator: ^NSComparisonResult (id <MKAnnotation > _Nonnull obj1, id <MKAnnotation > _Nonnull obj2) {
269
263
if (obj1.coordinate .latitude > obj2.coordinate .latitude ) return NSOrderedDescending;
270
264
if (obj1.coordinate .latitude < obj2.coordinate .latitude ) return NSOrderedAscending;
271
265
return NSOrderedSame;
272
266
}];
273
267
274
268
[_annotations insertObject: annotation atIndex: index];
275
- annotation.cluster = self;
276
269
277
270
self.coordinate = _annotations.firstObject .coordinate ;
278
271
279
272
_bounds = MKMapRectByAddingPoint (_bounds, MKMapPointForCoordinate (annotation.coordinate ));
280
273
}
281
274
}
282
275
283
- - (void )removeAnnotation : (id <CKAnnotation >)annotation {
284
- if (annotation. cluster == self) {
276
+ - (void )removeAnnotation : (id <MKAnnotation >)annotation {
277
+ if ([_annotations containsObject: self ] ) {
285
278
[_annotations removeObject: annotation];
286
- annotation.cluster = nil ;
287
279
288
280
self.coordinate = _annotations.firstObject .coordinate ;
289
281
0 commit comments