public List <IMKAnnotation> ClusteredAnnotationsWithinMapRect(MKMapRect rect, double zoomScale, Dictionary <IMKAnnotation, bool> filter) { double cellSize = FBCellSizeForZoomScale(zoomScale); if (RespondsToSelector != null) { cellSize *= RespondsToSelector(this); } double scaleFactor = zoomScale / cellSize; int minX = (int)Math.Floor(rect.MinX * scaleFactor); int maxX = (int)Math.Floor(rect.MaxX * scaleFactor); int minY = (int)Math.Floor(rect.MinY * scaleFactor); int maxY = (int)Math.Floor(rect.MaxY * scaleFactor); List <IMKAnnotation> clusteredAnnotations = new List <IMKAnnotation>(); lock (this) { for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { MKMapRect mapRect = new MKMapRect(x / scaleFactor, y / scaleFactor, 1.0 / scaleFactor, 1.0 / scaleFactor); FBBoundingBox mapBox = FBUtils.FBBoundingBoxForMapRect(mapRect); double totalLatitude = 0; double totalLongitude = 0; List <IMKAnnotation> annotations = new List <IMKAnnotation>(); _tree.EnumerateAnnotationsInBox(mapBox, delegate(IMKAnnotation annotation) { if (filter == null || filter[annotation]) { totalLatitude += annotation.Coordinate.Latitude; totalLongitude += annotation.Coordinate.Longitude; annotations.Add(annotation); } }); int count = annotations.Count; if (count == 1) { clusteredAnnotations.AddRange(annotations); } if (count > 1) { CLLocationCoordinate2D coordinate = new CLLocationCoordinate2D(totalLatitude / count, totalLongitude / count); FBAnnotationCluster cluster = new FBAnnotationCluster(coordinate); cluster.Annotations = annotations; clusteredAnnotations.Add(cluster); } } } } return(clusteredAnnotations); }
public List<IMKAnnotation> ClusteredAnnotationsWithinMapRect(MKMapRect rect, double zoomScale, Dictionary<IMKAnnotation, bool> filter) { double cellSize = FBCellSizeForZoomScale(zoomScale); if (RespondsToSelector != null) { cellSize *= RespondsToSelector(this); } double scaleFactor = zoomScale / cellSize; int minX = (int)Math.Floor(rect.MinX * scaleFactor); int maxX = (int)Math.Floor(rect.MaxX * scaleFactor); int minY = (int)Math.Floor(rect.MinY * scaleFactor); int maxY = (int)Math.Floor(rect.MaxY * scaleFactor); List<IMKAnnotation> clusteredAnnotations = new List<IMKAnnotation>(); lock (this) { for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { MKMapRect mapRect = new MKMapRect(x / scaleFactor, y / scaleFactor, 1.0 / scaleFactor, 1.0 / scaleFactor); FBBoundingBox mapBox = FBUtils.FBBoundingBoxForMapRect(mapRect); double totalLatitude = 0; double totalLongitude = 0; List<IMKAnnotation> annotations = new List<IMKAnnotation>(); _tree.EnumerateAnnotationsInBox(mapBox, delegate(IMKAnnotation annotation) { if (filter == null || filter[annotation]) { totalLatitude += annotation.Coordinate.Latitude; totalLongitude += annotation.Coordinate.Longitude; annotations.Add(annotation); } }); int count = annotations.Count; if (count == 1) clusteredAnnotations.AddRange(annotations); if (count > 1) { CLLocationCoordinate2D coordinate = new CLLocationCoordinate2D(totalLatitude/count, totalLongitude/count); FBAnnotationCluster cluster = new FBAnnotationCluster(coordinate); cluster.Annotations = annotations; clusteredAnnotations.Add(cluster); } } } } return clusteredAnnotations; }