Skip to content

Commit 057979d

Browse files
committed
Remove CKAnnotation protocol.
Fix selection.
1 parent 1bf7434 commit 057979d

14 files changed

+79
-115
lines changed

ClusterKit/Core/Algorithm/CKClusterAlgorithm.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ - (instancetype)init {
3838
NSArray *annotations = [tree annotationsInRect:rect];
3939
NSMutableArray *clusters = [NSMutableArray arrayWithCapacity:annotations.count];
4040

41-
for (id<CKAnnotation> annotation in annotations) {
41+
for (id<MKAnnotation> annotation in annotations) {
4242
CKCluster *cluster = [self clusterWithCoordinate:annotation.coordinate];
4343
[cluster addAnnotation:annotation];
4444
[clusters addObject:cluster];

ClusterKit/Core/Algorithm/CKGridBasedAlgorithm.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ - (instancetype)init {
4242
// Divide the whole map into a numCells x numCells grid and assign annotations to them.
4343
long numCells = (long)ceil(256 * pow(2, zoom) / self.cellSize);
4444

45-
for (id<CKAnnotation> annotation in annotations) {
45+
for (id<MKAnnotation> annotation in annotations) {
4646

4747
MKMapPoint point = MKMapPointForCoordinate(annotation.coordinate);
4848
NSUInteger col = numCells * point.x / MKMapSizeWorld.width;

ClusterKit/Core/Algorithm/CKNonHierarchicalDistanceBasedAlgorithm.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ - (instancetype)init {
4646

4747
NSMutableArray<CKCluster *> *clusters = [[NSMutableArray alloc] init];
4848

49-
NSMapTable<id<CKAnnotation>, CKCandidate *> *visited = [NSMapTable strongToStrongObjectsMapTable];
49+
NSMapTable<id<MKAnnotation>, CKCandidate *> *visited = [NSMapTable strongToStrongObjectsMapTable];
5050

5151
@synchronized(tree) {
5252

5353
NSArray *annotations = [tree annotationsInRect:rect];
5454

55-
for (id<CKAnnotation> annotation in annotations) {
55+
for (id<MKAnnotation> annotation in annotations) {
5656

5757
if ([visited objectForKey:annotation]) {
5858
continue;
@@ -64,7 +64,7 @@ - (instancetype)init {
6464
MKMapRect clusterRect = CKCreateRectFromSpan(annotation.coordinate, zoomSpecificSpan);
6565
NSArray *neighbors = [tree annotationsInRect:clusterRect];
6666

67-
for (id<CKAnnotation> neighbor in neighbors) {
67+
for (id<MKAnnotation> neighbor in neighbors) {
6868

6969
CKCandidate *candidate = [visited objectForKey:neighbor];
7070

ClusterKit/Core/CKCluster.h

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ MK_EXTERN MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point);
3838

3939
@class CKCluster;
4040

41-
#pragma - CKAnnotation protocol
42-
43-
/**
44-
The CKAnnotation protocol is used to provide clusterized place information to a map. To use this protocol, you adopt it in any custom objects that store or represent a place data. Annotation objects do not provide the visual representation of the place but typically coordinate and parent cluster.
45-
@discussion An object that adopts this protocol must implement the coordinate and cluster properties. The other methods of this protocol are optional.
46-
*/
47-
@protocol CKAnnotation <MKAnnotation>
48-
49-
/**
50-
The cluster that the annotation is related to.
51-
*/
52-
@property (nonatomic, weak, nullable) CKCluster *cluster;
53-
54-
@end
55-
5641
#pragma - Cluster definitions
5742

5843
/**
@@ -83,7 +68,7 @@ MK_EXTERN MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point);
8368
/**
8469
Cluster annotation array.
8570
*/
86-
@property (nonatomic, readonly, copy) NSArray<id<CKAnnotation>> *annotations;
71+
@property (nonatomic, readonly, copy) NSArray<id<MKAnnotation>> *annotations;
8772

8873
/**
8974
The number of annotations in the cluster.
@@ -94,13 +79,13 @@ MK_EXTERN MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point);
9479
The first annotation in the cluster.
9580
If the cluster is empty, returns nil.
9681
*/
97-
@property (nonatomic, readonly, nullable) id<CKAnnotation> firstAnnotation;
82+
@property (nonatomic, readonly, nullable) id<MKAnnotation> firstAnnotation;
9883

9984
/**
10085
The last annotation in the cluster.
10186
If the cluster is empty, returns nil.
10287
*/
103-
@property (nonatomic, readonly, nullable) id<CKAnnotation> lastAnnotation;
88+
@property (nonatomic, readonly, nullable) id<MKAnnotation> lastAnnotation;
10489

10590
/**
10691
Represents a rectangular bounding box on the Earth's projection.
@@ -112,14 +97,14 @@ MK_EXTERN MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point);
11297
11398
@param annotation The annotation to add.
11499
*/
115-
- (void)addAnnotation:(id<CKAnnotation>)annotation;
100+
- (void)addAnnotation:(id<MKAnnotation>)annotation;
116101

117102
/**
118103
Removes a given annotation from the cluster.
119104
120105
@param annotation The annotation to remove.
121106
*/
122-
- (void)removeAnnotation:(id<CKAnnotation>)annotation;
107+
- (void)removeAnnotation:(id<MKAnnotation>)annotation;
123108

124109
/**
125110
Returns the annotation at the given index.
@@ -128,7 +113,7 @@ MK_EXTERN MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point);
128113
@param index An annotation index within the bounds of the array.
129114
@return The annotation located at index.
130115
*/
131-
- (id<CKAnnotation>)annotationAtIndex:(NSUInteger)index;
116+
- (id<MKAnnotation>)annotationAtIndex:(NSUInteger)index;
132117

133118
/**
134119
Returns a Boolean value that indicates whether a given annotation is present in the cluster.
@@ -137,20 +122,20 @@ MK_EXTERN MKMapRect MKMapRectByAddingPoint(MKMapRect rect, MKMapPoint point);
137122
@param annotation An annotation.
138123
@return YES if the gievn annotation is present in the cluster, otherwise NO.
139124
*/
140-
- (BOOL)containsAnnotation:(id<CKAnnotation>)annotation;
125+
- (BOOL)containsAnnotation:(id<MKAnnotation>)annotation;
141126

142127
/**
143128
Returns the annotation at the specified index.
144129
This method has the same behavior as the annotationAtIndex: method.
145130
If index is beyond the end of the cluster (that is, if index is greater than or equal to the value returned by count), an NSRangeException is raised.
146131
You shouldn’t need to call this method directly. Instead, this method is called when accessing an annotation by index using subscripting.
147132
148-
`id<CKAnnotation> value = cluster[3]; // equivalent to [cluster annotationAtIndex:3]`
133+
`id<MKAnnotation> value = cluster[3]; // equivalent to [cluster annotationAtIndex:3]`
149134
150135
@param index An index within the bounds of the cluster.
151136
@return The annotation located at index.
152137
*/
153-
- (id<CKAnnotation>)objectAtIndexedSubscript:(NSUInteger)index;
138+
- (id<MKAnnotation>)objectAtIndexedSubscript:(NSUInteger)index;
154139

155140
/**
156141
Returns a Boolean value that indicates whether the receiver and a given cluster are equal.

ClusterKit/Core/CKCluster.m

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

ClusterKit/Core/CKClusterManager.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ FOUNDATION_EXTERN const double kCKMarginFactorWorld;
4747
4848
@return Yes to permit clusterization of the given annotation.
4949
*/
50-
- (BOOL)clusterManager:(CKClusterManager *)clusterManager shouldClusterAnnotation:(id<CKAnnotation>)annotation;
50+
- (BOOL)clusterManager:(CKClusterManager *)clusterManager shouldClusterAnnotation:(id<MKAnnotation>)annotation;
5151

5252
/**
5353
Tells the delegate to perform an animation.
@@ -90,7 +90,7 @@ FOUNDATION_EXTERN const double kCKMarginFactorWorld;
9090
/**
9191
The currently selected annotation.
9292
*/
93-
@property (nonatomic,readonly) id<CKAnnotation> selectedAnnotation;
93+
@property (nonatomic,readonly) id<MKAnnotation> selectedAnnotation;
9494

9595
/**
9696
The current cluster array.
@@ -110,49 +110,49 @@ FOUNDATION_EXTERN const double kCKMarginFactorWorld;
110110
/**
111111
The annotations to clusterize.
112112
*/
113-
@property (nonatomic,copy) NSArray<id<CKAnnotation>> *annotations;
113+
@property (nonatomic,copy) NSArray<id<MKAnnotation>> *annotations;
114114

115115
/**
116116
Adds an annotation.
117117
118118
@param annotation The annotation to add.
119119
*/
120-
- (void)addAnnotation:(id<CKAnnotation>)annotation;
120+
- (void)addAnnotation:(id<MKAnnotation>)annotation;
121121

122122
/**
123123
Adds annotations.
124124
125125
@param annotations Annotations to add.
126126
*/
127-
- (void)addAnnotations:(NSArray<id<CKAnnotation>> *)annotations;
127+
- (void)addAnnotations:(NSArray<id<MKAnnotation>> *)annotations;
128128

129129
/**
130130
Removes an annotation.
131131
132132
@param annotation The annotation to remove.
133133
*/
134-
- (void)removeAnnotation:(id<CKAnnotation>)annotation;
134+
- (void)removeAnnotation:(id<MKAnnotation>)annotation;
135135

136136
/**
137137
Removes annotations.
138138
139139
@param annotations Annotations to remove.
140140
*/
141-
- (void)removeAnnotations:(NSArray<id<CKAnnotation>> *)annotations;
141+
- (void)removeAnnotations:(NSArray<id<MKAnnotation>> *)annotations;
142142

143143
/**
144144
Selects an annotation. Look for the annotation in clusters and extract it if necessary.
145145
146146
@param annotation The annotation to be selected.
147147
*/
148-
- (void)selectAnnotation:(id<CKAnnotation>)annotation animated:(BOOL)animated;
148+
- (void)selectAnnotation:(id<MKAnnotation>)annotation animated:(BOOL)animated;
149149

150150
/**
151151
Deselects an annotation.
152152
153153
@param annotation The annotation to be deselected.
154154
*/
155-
- (void)deselectAnnotation:(nullable id<CKAnnotation>)annotation animated:(BOOL)animated;
155+
- (void)deselectAnnotation:(nullable id<MKAnnotation>)annotation animated:(BOOL)animated;
156156

157157
/**
158158
Updates displayed clusters.

0 commit comments

Comments
 (0)