@@ -23,7 +23,8 @@ public class FBClusteringManager : NSObject {
2323
2424 var lock : NSRecursiveLock = NSRecursiveLock ( )
2525
26-
26+ public var maxZoomLevel = 1.0
27+
2728 public override init ( ) {
2829 super. init ( )
2930 }
@@ -55,25 +56,25 @@ public class FBClusteringManager : NSObject {
5556
5657 let cellSize : CGFloat = FBClusteringManager . FBCellSizeForZoomScale ( MKZoomScale ( zoomScale) )
5758
58- // if delegate?.respondsToSelector("cellSizeFactorForCoordinator:") {
59- // cellSize *= delegate.cellSizeFactorForCoordinator(self)
60- // }
59+ // if delegate?.respondsToSelector("cellSizeFactorForCoordinator:") {
60+ // cellSize *= delegate.cellSizeFactorForCoordinator(self)
61+ // }
6162
6263 let scaleFactor : Double = zoomScale / Double( cellSize)
6364
6465 let minX : Int = Int ( floor ( MKMapRectGetMinX ( rect) * scaleFactor) )
6566 let maxX : Int = Int ( floor ( MKMapRectGetMaxX ( rect) * scaleFactor) )
6667 let minY : Int = Int ( floor ( MKMapRectGetMinY ( rect) * scaleFactor) )
6768 let maxY : Int = Int ( floor ( MKMapRectGetMaxY ( rect) * scaleFactor) )
68-
69+
6970 var clusteredAnnotations = [ MKAnnotation] ( )
70-
71+
7172 lock. lock ( )
72-
73+
7374 for i in minX... maxX {
74-
75+
7576 for j in minY... maxY {
76-
77+
7778 let mapPoint = MKMapPoint ( x: Double ( i) / scaleFactor, y: Double ( j) / scaleFactor)
7879
7980 let mapSize = MKMapSize ( width: 1.0 / scaleFactor, height: 1.0 / scaleFactor)
@@ -98,27 +99,23 @@ public class FBClusteringManager : NSObject {
9899 clusteredAnnotations += annotations
99100 }
100101
101- if count > 1 {
102+ if count > 1 && zoomScale < self . maxZoomLevel {
102103 let coordinate = CLLocationCoordinate2D (
103104 latitude: CLLocationDegrees ( totalLatitude) / CLLocationDegrees( count) ,
104105 longitude: CLLocationDegrees ( totalLongitude) / CLLocationDegrees( count)
105106 )
106107 let cluster = FBAnnotationCluster ( )
107108 cluster. coordinate = coordinate
108109 cluster. annotations = annotations
109-
110- print ( " cluster.annotations.count:: \( cluster. annotations. count) " )
111-
112110 clusteredAnnotations. append ( cluster)
111+ } else {
112+ clusteredAnnotations += annotations
113113 }
114-
115-
116-
117114 }
118-
115+
119116 }
120117
121-
118+
122119 lock. unlock ( )
123120
124121 return clusteredAnnotations
@@ -140,7 +137,7 @@ public class FBClusteringManager : NSObject {
140137 public func displayAnnotations( annotations: [ MKAnnotation ] , onMapView mapView: MKMapView ) {
141138
142139 dispatch_async ( dispatch_get_main_queue ( ) ) {
143-
140+
144141 let before = NSMutableSet ( array: mapView. annotations)
145142 before. removeObject ( mapView. userLocation)
146143 let after = NSSet ( array: annotations)
@@ -150,7 +147,7 @@ public class FBClusteringManager : NSObject {
150147 toAdd. minusSet ( toKeep as Set < NSObject > )
151148 let toRemove = NSMutableSet ( set: before)
152149 toRemove. minusSet ( after as Set < NSObject > )
153-
150+
154151 if let toAddAnnotations = toAdd. allObjects as? [ MKAnnotation ] {
155152 mapView. addAnnotations ( toAddAnnotations)
156153 }
0 commit comments