Skip to content

Commit

Permalink
update 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Russo authored and Giuseppe Russo committed Mar 24, 2016
1 parent 048bcf6 commit 0d98a9c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
9 changes: 9 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!

target 'FBAnnotationClusteringSwift_Example' do
pod 'FBAnnotationClusteringSwift’, :path => '../'
end

4 changes: 2 additions & 2 deletions FBAnnotationClusteringSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

s.description = <<-DESC
Expand All @@ -20,7 +20,7 @@ Swift translation of FB Annotation Clustering, which clusters pins on the map fo
s.author = { "Giuseppe Russo" => "[email protected]" }
s.source = { :git => "https://github.com/freemiumdev/FBAnnotationClusteringSwift.git", :tag => s.version}

s.platform = :ios, '9.0'
s.platform = :ios, '8.0'
s.requires_arc = true

s.source_files = 'Pod/Classes/**/*'
Expand Down
37 changes: 17 additions & 20 deletions Pod/Classes/FBClusteringManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class FBClusteringManager : NSObject {

var lock:NSRecursiveLock = NSRecursiveLock()


public var maxZoomLevel = 1.0

public override init(){
super.init()
}
Expand Down Expand Up @@ -55,25 +56,25 @@ public class FBClusteringManager : NSObject {

let cellSize:CGFloat = FBClusteringManager.FBCellSizeForZoomScale(MKZoomScale(zoomScale))

// if delegate?.respondsToSelector("cellSizeFactorForCoordinator:") {
// cellSize *= delegate.cellSizeFactorForCoordinator(self)
// }
// if delegate?.respondsToSelector("cellSizeFactorForCoordinator:") {
// cellSize *= delegate.cellSizeFactorForCoordinator(self)
// }

let scaleFactor:Double = zoomScale / Double(cellSize)

let minX:Int = Int(floor(MKMapRectGetMinX(rect) * scaleFactor))
let maxX:Int = Int(floor(MKMapRectGetMaxX(rect) * scaleFactor))
let minY:Int = Int(floor(MKMapRectGetMinY(rect) * scaleFactor))
let maxY:Int = Int(floor(MKMapRectGetMaxY(rect) * scaleFactor))

var clusteredAnnotations = [MKAnnotation]()

lock.lock()

for i in minX...maxX {

for j in minY...maxY {

let mapPoint = MKMapPoint(x: Double(i)/scaleFactor, y: Double(j)/scaleFactor)

let mapSize = MKMapSize(width: 1.0/scaleFactor, height: 1.0/scaleFactor)
Expand All @@ -98,27 +99,23 @@ public class FBClusteringManager : NSObject {
clusteredAnnotations += annotations
}

if count > 1 {
if count > 1 && zoomScale < self.maxZoomLevel {
let coordinate = CLLocationCoordinate2D(
latitude: CLLocationDegrees(totalLatitude)/CLLocationDegrees(count),
longitude: CLLocationDegrees(totalLongitude)/CLLocationDegrees(count)
)
let cluster = FBAnnotationCluster()
cluster.coordinate = coordinate
cluster.annotations = annotations

print("cluster.annotations.count:: \(cluster.annotations.count)")

clusteredAnnotations.append(cluster)
} else {
clusteredAnnotations += annotations
}



}

}


lock.unlock()

return clusteredAnnotations
Expand All @@ -140,7 +137,7 @@ public class FBClusteringManager : NSObject {
public func displayAnnotations(annotations: [MKAnnotation], onMapView mapView:MKMapView){

dispatch_async(dispatch_get_main_queue()) {

let before = NSMutableSet(array: mapView.annotations)
before.removeObject(mapView.userLocation)
let after = NSSet(array: annotations)
Expand All @@ -150,7 +147,7 @@ public class FBClusteringManager : NSObject {
toAdd.minusSet(toKeep as Set<NSObject>)
let toRemove = NSMutableSet(set: before)
toRemove.minusSet(after as Set<NSObject>)

if let toAddAnnotations = toAdd.allObjects as? [MKAnnotation]{
mapView.addAnnotations(toAddAnnotations)
}
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,12 @@ extension ViewController: MKMapViewDelegate {

For image's cluster
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

## Run Example
If you want run example, before to open Xcode the first time, open Terminal in Example folder and run the command:

```
pod install
```

After than open the .xworkspace file generated.

0 comments on commit 0d98a9c

Please sign in to comment.