public override List <CKCluster> ClustersInRect(MKMapRect rect, double zoom, Tree.ICKAnnotationTree tree) { var zoomSpecificSpan = 100 * this.CellSize / Math.Pow(2, zoom + 8); var clusters = new List <CKCluster>(); var visited = new Dictionary <CKAnnotation, CKCandidate>(); var annotations = tree.AnnotationsInRect(rect); foreach (var ann in annotations) { if (visited.ContainsKey(ann)) { continue; } var cluster = this.ClusterWithCoordinate(ann.Coordinate); clusters.Add(cluster); MKMapRect clusterRect = this.CKCreateRectFromSpan(ann.Coordinate, zoomSpecificSpan); var neighbors = tree.AnnotationsInRect(clusterRect); foreach (var neighbor in neighbors) { var distance = CKDistance.GetDistance(neighbor.Coordinate, cluster.Coordinate); CKCandidate candidate; if (visited.TryGetValue(neighbor, out candidate)) { if (candidate.Distance < distance) { continue; } candidate.Cluster.RemoveAnnotation(neighbor); } else { candidate = new CKCandidate(); visited.Add(neighbor, candidate); } candidate.Cluster = cluster; candidate.Distance = distance; cluster.AddAnnotation(neighbor); } } return(clusters); }
public override List <CKCluster> ClustersInRect(MapKit.MKMapRect rect, double zoom, Tree.ICKAnnotationTree tree) { var clusters = new Dictionary <double, CKCluster>(); var annotations = tree.AnnotationsInRect(rect); var numCells = Math.Ceiling(256 * Math.Pow(2, zoom) / this.CellSize); foreach (var ann in annotations) { var point = MKMapPoint.FromCoordinate(ann.Coordinate); var col = numCells * point.X / MKMapSize.World.Width; var row = numCells * point.Y / MKMapSize.World.Height; var key = numCells * row + col; CKCluster cluster; if (clusters.ContainsKey(key)) { cluster = clusters[key]; } else { cluster = this.ClusterWithCoordinate(ann.Coordinate); clusters[key] = cluster; } cluster.AddAnnotation(ann); } return(clusters.Values.ToList()); }