Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Total number of annotations on cluster does not match the number of annotations I added to the manager #130

Open
4 tasks done
sarbogast opened this issue Sep 21, 2020 · 4 comments

Comments

@sarbogast
Copy link

Description
It is not necessarily a bug, maybe I'm not using the library right.
When I add annotations to the manager I have a certain number of annotations in there, eg 362
But the if I sum up the numbers in all the cluster annotation view and isolated non-clustered annotations, or simply zoom out to the max, the total number of annotations is different (eg 231). And I get that number both on manager.annotations.count and on annotation.annotations.count:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        if let annotation = annotation as? ClusterAnnotation {
            let identifier = "Cluster"
            let annotationView = mapView.annotationView(of: HTImageCountClusterAnnotationView.self, annotation: annotation, reuseIdentifier: identifier)
            annotationView.countLabel.textColor = UIColor.black
            annotationView.image = UIImage(named: "clusterpin")
            annotationView.canShowCallout = false
            print("Number of annotations in cluster: \(annotation.annotations.count)")
            print("Number of annotations in manager: \(manager.annotations.count)")
            return annotationView
        } else {
            ...
        }
    }

This is how I initialize my manager:

private lazy var manager: ClusterManager = { [unowned self] in
        let manager = ClusterManager()
        manager.delegate = self
        manager.maxZoomLevel = 17
        manager.minCountForClustering = 2
        manager.clusterPosition = .nearCenter
        manager.shouldRemoveInvisibleAnnotations = false
        return manager
    }()

I don't understand this discrepancy. I don't remove any annotation from the manager.

Smartphone

  • Device: iPhone 11 Pro
  • OS: iOS14
  • Version: 3.0.3

Checklist

@CeccoCQ
Copy link

CeccoCQ commented Oct 2, 2020

Same issue here.

@imnaveensharma
Copy link

In my case, the problem is solved by changing the default values of the given 3 properties.

manager.shouldRemoveInvisibleAnnotations = false
manager.shouldDistributeAnnotationsOnSameCoordinate = false
manager.distanceFromContestedLocation = 0

Full Code is:

private lazy var clusterManager: ClusterManager = { [unowned self] in
let manager = ClusterManager()
manager.delegate = self
manager.maxZoomLevel = 20//17
manager.minCountForClustering = 2
manager.clusterPosition = .nearCenter
manager.shouldRemoveInvisibleAnnotations = false
manager.shouldDistributeAnnotationsOnSameCoordinate = false
manager.distanceFromContestedLocation = 0
return manager
}()

@matopeto
Copy link

Same issue, fix by @imnaveensharma is not working for me

@b00tsy
Copy link

b00tsy commented Apr 21, 2022

same problem here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants