Skip to content

Commit

Permalink
2.4.5 (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
efremidze authored Mar 7, 2019
1 parent 0926f8e commit 08e4c88
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## [Version 2.4.5](https://github.com/efremidze/Cluster/releases/tag/2.4.5)
Released on 2019-03-07

- Fixed distributeAnnotations bug

## [Version 2.4.4](https://github.com/efremidze/Cluster/releases/tag/2.4.4)
Released on 2019-02-11

Expand Down
2 changes: 1 addition & 1 deletion Cluster.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Cluster'
s.version = '2.4.4'
s.version = '2.4.5'
s.summary = 'Map Clustering Library'
s.homepage = 'https://github.com/efremidze/Cluster'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
4 changes: 2 additions & 2 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ extension ViewController: MKMapViewDelegate {

extension ViewController: ClusterManagerDelegate {

func cellSize(for zoomLevel: Double) -> Double {
return 0 // default
func cellSize(for zoomLevel: Double) -> Double? {
return nil // default
}

func shouldClusterAnnotation(_ annotation: MKAnnotation) -> Bool {
Expand Down
14 changes: 8 additions & 6 deletions Sources/Cluster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public protocol ClusterManagerDelegate: class {

- Returns: The cell size at the given zoom level.
*/
func cellSize(for zoomLevel: Double) -> Double
func cellSize(for zoomLevel: Double) -> Double?

/**
Whether to cluster the given annotation.
Expand All @@ -32,8 +32,8 @@ public protocol ClusterManagerDelegate: class {
}

public extension ClusterManagerDelegate {
func cellSize(for zoomLevel: Double) -> Double {
return 0
func cellSize(for zoomLevel: Double) -> Double? {
return nil
}

func shouldClusterAnnotation(_ annotation: MKAnnotation) -> Bool {
Expand Down Expand Up @@ -304,7 +304,7 @@ open class ClusterManager {

// handle annotations on the same coordinate
if shouldDistributeAnnotationsOnSameCoordinate {
distributeAnnotations(annotations: annotations) // buggy (modifying coordinate)
distributeAnnotations(annotations: annotations, tree: tree, mapRect: mapRect)
}

// handle clustering
Expand All @@ -322,14 +322,16 @@ open class ClusterManager {
return allAnnotations
}

func distributeAnnotations(annotations: [MKAnnotation]) {
func distributeAnnotations(annotations: [MKAnnotation], tree: QuadTree, mapRect: MKMapRect) {
let hash = Dictionary(grouping: annotations) { $0.coordinate }
for value in hash.values where value.count > 1 {
for (index, annotation) in value.enumerated() {
tree.remove(annotation)
let distanceFromContestedLocation = 3 * Double(value.count) / 2
let radiansBetweenAnnotations = (.pi * 2) / Double(value.count)
let bearing = radiansBetweenAnnotations * Double(index)
(annotation as? MKPointAnnotation)?.coordinate = annotation.coordinate.coordinate(onBearingInRadians: bearing, atDistanceInMeters: distanceFromContestedLocation)
tree.add(annotation)
}
}
}
Expand Down Expand Up @@ -382,7 +384,7 @@ open class ClusterManager {
}

func cellSize(for zoomLevel: Double) -> Double {
if let cellSize = delegate?.cellSize(for: zoomLevel), cellSize > 0 {
if let cellSize = delegate?.cellSize(for: zoomLevel) {
return cellSize
}
switch zoomLevel {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.4.4</string>
<string>2.4.5</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 08e4c88

Please sign in to comment.