Skip to content

Commit c994b49

Browse files
committed
Fix annotation selection
1 parent f5be48d commit c994b49

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

ClusterKit/Core/CKClusterManager.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ - (void)deselectAnnotation:(id<MKAnnotation>)annotation animated:(BOOL)animated
160160
#pragma mark - Private
161161

162162
- (void)updateMapRect:(MKMapRect)visibleMapRect animated:(BOOL)animated {
163-
164-
if (! self.tree || MKMapRectIsNull(visibleMapRect) || MKMapRectIsEmpty(visibleMapRect)) {
163+
if (!self.tree || MKMapRectIsNull(visibleMapRect) || MKMapRectIsEmpty(visibleMapRect)) {
165164
return;
166165
}
167166

@@ -200,12 +199,12 @@ - (void)updateMapRect:(MKMapRect)visibleMapRect animated:(BOOL)animated {
200199
}
201200

202201
- (void)setSelectedCluster:(CKCluster *)selectedCluster animated:(BOOL)animated {
203-
if (selectedCluster == _selectedCluster) {
202+
if (selectedCluster == self.selectedCluster) {
204203
return;
205204
}
206205

207-
CKCluster *prev = _selectedCluster;
208-
_selectedCluster = selectedCluster;
206+
CKCluster *prev = self.selectedCluster;
207+
self.selectedCluster = selectedCluster;
209208

210209
if (prev) {
211210
[_clusters addObject:prev];
@@ -219,6 +218,10 @@ - (void)setSelectedCluster:(CKCluster *)selectedCluster animated:(BOOL)animated
219218
}
220219

221220
- (CKCluster *)clusterForAnnotation:(id<MKAnnotation>)annotation {
221+
if ([self.selectedCluster containsAnnotation:annotation]) {
222+
return self.selectedCluster;
223+
}
224+
222225
for (CKCluster *cluster in _clusters) {
223226
if ([cluster containsAnnotation:annotation]) {
224227
return cluster;

ClusterKit/MapKit/MKMapView+ClusterKit.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ - (void)removeClusters:(NSArray<CKCluster *> *)clusters {
6161
[self removeAnnotations:clusters];
6262
}
6363

64+
- (void)selectCluster:(CKCluster *)cluster animated:(BOOL)animated {
65+
if (![self.selectedAnnotations containsObject:cluster]) {
66+
[self selectAnnotation:cluster animated:animated];
67+
}
68+
}
69+
70+
- (void)deselectCluster:(CKCluster *)cluster animated:(BOOL)animated {
71+
if ([self.selectedAnnotations containsObject:cluster]) {
72+
[self deselectAnnotation:cluster animated:animated];
73+
}
74+
}
75+
6476
- (void)performAnimations:(NSArray<CKClusterAnimation *> *)animations completion:(void (^__nullable)(BOOL finished))completion {
6577

6678
for (CKClusterAnimation *animation in animations) {
@@ -91,12 +103,4 @@ - (void)performAnimations:(NSArray<CKClusterAnimation *> *)animations completion
91103
}
92104
}
93105

94-
- (void)selectCluster:(CKCluster *)cluster animated:(BOOL)animated {
95-
[self selectAnnotation:cluster animated:animated];
96-
}
97-
98-
- (void)deselectCluster:(CKCluster *)cluster animated:(BOOL)animated {
99-
[self deselectAnnotation:cluster animated:animated];
100-
}
101-
102106
@end

ClusterKit/Mapbox/MGLMapView+ClusterKit.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ - (MKMapRect)visibleMapRect {
8888
return MKMapRectMake(x, y, width, height);
8989
}
9090

91-
- (void)selectCluster:(CKCluster *)cluster animated:(BOOL)animated {
92-
[self selectAnnotation:cluster animated:animated];
93-
}
94-
95-
- (void)deselectCluster:(CKCluster *)cluster animated:(BOOL)animated {
96-
[self deselectAnnotation:cluster animated:animated];
97-
}
98-
9991
- (void)addClusters:(NSArray<CKCluster *> *)clusters {
10092
[self addAnnotations:clusters];
10193
}
@@ -104,6 +96,18 @@ - (void)removeClusters:(NSArray<CKCluster *> *)clusters {
10496
[self removeAnnotations:clusters];
10597
}
10698

99+
- (void)selectCluster:(CKCluster *)cluster animated:(BOOL)animated {
100+
if (![self.selectedAnnotations containsObject:cluster]) {
101+
[self selectAnnotation:cluster animated:animated];
102+
}
103+
}
104+
105+
- (void)deselectCluster:(CKCluster *)cluster animated:(BOOL)animated {
106+
if ([self.selectedAnnotations containsObject:cluster]) {
107+
[self deselectAnnotation:cluster animated:animated];
108+
}
109+
}
110+
107111
- (void)performAnimations:(NSArray<CKClusterAnimation *> *)animations completion:(void (^__nullable)(BOOL finished))completion {
108112

109113
for (CKClusterAnimation *animation in animations) {

0 commit comments

Comments
 (0)