Skip to content

Commit 0d98a9c

Browse files
Giuseppe RussoGiuseppe Russo
authored andcommitted
update 1.0.1
1 parent 048bcf6 commit 0d98a9c

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

Example/Podfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Uncomment this line to define a global platform for your project
2+
# platform :ios, '8.0'
3+
# Uncomment this line if you're using Swift
4+
use_frameworks!
5+
6+
target 'FBAnnotationClusteringSwift_Example' do
7+
pod 'FBAnnotationClusteringSwift’, :path => '../'
8+
end
9+

FBAnnotationClusteringSwift.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "FBAnnotationClusteringSwift"
11-
s.version = "1.0.0"
11+
s.version = "1.0.1"
1212
s.summary = "This is a Swift translation of FBAnnotationClustering. Aggregates map pins into a single numbered cluster."
1313

1414
s.description = <<-DESC
@@ -20,7 +20,7 @@ Swift translation of FB Annotation Clustering, which clusters pins on the map fo
2020
s.author = { "Giuseppe Russo" => "freemiumdev@outlook.it" }
2121
s.source = { :git => "https://github.com/freemiumdev/FBAnnotationClusteringSwift.git", :tag => s.version}
2222

23-
s.platform = :ios, '9.0'
23+
s.platform = :ios, '8.0'
2424
s.requires_arc = true
2525

2626
s.source_files = 'Pod/Classes/**/*'

Pod/Classes/FBClusteringManager.swift

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

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,12 @@ extension ViewController: MKMapViewDelegate {
112112

113113
For image's cluster
114114
You can use those provided by me, or you can pass the name of the image you have in your project. Remember you will need 3 different images depending on the cluster size
115+
116+
## Run Example
117+
If you want run example, before to open Xcode the first time, open Terminal in Example folder and run the command:
118+
119+
```
120+
pod install
121+
```
122+
123+
After than open the .xworkspace file generated.

0 commit comments

Comments
 (0)