ribl / FBAnnotationClusteringSwift

Swift translation of FB Annotation Clustering, which clusters pins on the map for iOS.
http://ribl.co/blog/2015/05/28/map-clustering-with-swift-how-we-implemented-it-into-the-ribl-ios-app/
MIT License
311 stars 109 forks source link

Unclustering as map zooms out #42

Open SeanMurphy15 opened 8 years ago

SeanMurphy15 commented 8 years ago

My annotations will merge and un-merge as I zoom out creating a kind of glitchy looking display. Ideally, I'd like the annotations that are within a cluster to remain there as the map zooms out. I've messed with several different variable on the FBClusteringManager's "FBZoomScaleToZoomLevel" switch statement with no luck. Below is what I have to display annotations on the map on my viewcontroller:

func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) { let array: [MKAnnotation] = self.createAnnotationsForVideos(self.mapVideos) self.clusteringManager.addAnnotations(array) let mapBoundsWidth = Double(self.mapView.bounds.size.width) let mapRectWidth: Double = self.mapView.visibleMapRect.size.width let scale: Double = mapBoundsWidth / mapRectWidth let annotationArray = self.clusteringManager.clusteredAnnotationsWithinMapRect(self.mapView.visibleMapRect, withZoomScale: scale) self.clusteringManager.displayAnnotations(annotationArray, onMapView: self.mapView)

}
riccardoch commented 8 years ago

I've commented these lines in FBClusteringManager.swift

let annotationsOnlyPredicate = NSPredicate(format: "SELF isKindOfClass:%@", argumentArray: [FBAnnotationCluster.self])
toRemove.filterUsingPredicate(annotationsOnlyPredicate)
lblasa commented 7 years ago

@riccardoch it seems to work if I understood the initial problem correctly as I was experiencing the same problem.

Clusters work fine when zooming in or out. The problem is that regular pins were not getting re-clustered when zooming out. This is less than ideal.

Commenting those lines seem to fix the problem. Thanks.