Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CCHMapClusterController/CCHMapClusterController.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,25 @@
/**
Adds annotations and immediately updates clustering.
@param annotations Annotations to add.
@param completionHandler Called when the clustering finished updating.
@param completionHandler Called on main thread when the clustering finished updating.
*/
- (void)addAnnotations:(NSArray *)annotations withCompletionHandler:(void (^)())completionHandler;

/**
Removes annotations and immediately updates clustering.
@param annotations Annotations to add.
@param completionHandler Called when the clustering finished updating.
@param annotations Annotations to remove.
@param completionHandler Called on main thread when the clustering finished updating.
*/
- (void)removeAnnotations:(NSArray *)annotations withCompletionHandler:(void (^)())completionHandler;

/**
Removes annotations, then adds new annotations and immediately updates clustering.
@param annotationsToRemove Annotations to remove.
@param annotationsToAdd Annotations to add.
@param completionHandler Called on main thread when the clustering finished updating.
*/
- (void)removeAnnotations:(NSArray *)annotationsToRemove andAddAnnotations:(NSArray *)annotationsToAdd withCompletionHandler:(void (^)())completionHandler;

/**
Zooms to the position of the cluster that contains the given annotation and selects the cluster's annotation view.
@param annotation The annotation to look for. Uses `isEqual:` to check for a matching annotation previously added with `addAnnotations:withCompletionHandler:`.
Expand Down
22 changes: 22 additions & 0 deletions CCHMapClusterController/CCHMapClusterController.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ - (void)removeAnnotations:(NSArray *)annotations withCompletionHandler:(void (^)
}];
}

- (void)removeAnnotations:(NSArray *)annotationsToRemove andAddAnnotations:(NSArray *)annotationsToAdd withCompletionHandler:(void (^)())completionHandler
{
[self cancelAllClusterOperations];

[self.allAnnotations minusSet:[NSSet setWithArray:annotationsToRemove]];
[self.allAnnotations addObjectsFromArray:annotationsToAdd];

[self.backgroundQueue addOperationWithBlock:^{
BOOL updatedRemove = [self.allAnnotationsMapTree removeAnnotations:annotationsToRemove];
BOOL updatedAdd = [self.allAnnotationsMapTree addAnnotations:annotationsToAdd];
BOOL updated = updatedRemove || updatedAdd;

dispatch_async(dispatch_get_main_queue(), ^{
if (updated && !self.isRegionChanging) {
[self updateAnnotationsWithCompletionHandler:completionHandler];
} else if (completionHandler) {
completionHandler();
}
});
}];
}

- (void)updateAnnotationsWithCompletionHandler:(void (^)())completionHandler
{
[self cancelAllClusterOperations];
Expand Down