From cf3cc22f4b1fb10a150a9346cd327c89708da434 Mon Sep 17 00:00:00 2001 From: Falko Buttler Date: Mon, 20 Jun 2016 23:22:50 -0700 Subject: [PATCH] Fixed race condition with calculation for left and right coordinates of map view to calculate length This caused the cell size sometimes to be 0 due to a race condition when converting coordinates from the map view to its super view. When that happened, all annotations become invisible. This constantly happens when rotating, especially in flyover mode. Instead we are now calculating it against its own view, which always returns consistent and valid results. --- CCHMapClusterController/CCHMapClusterControllerUtils.h | 6 +----- CCHMapClusterController/CCHMapClusterControllerUtils.m | 10 +++------- CCHMapClusterController/CCHMapClusterOperation.m | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/CCHMapClusterController/CCHMapClusterControllerUtils.h b/CCHMapClusterController/CCHMapClusterControllerUtils.h index 9c5f14d..0369528 100644 --- a/CCHMapClusterController/CCHMapClusterControllerUtils.h +++ b/CCHMapClusterController/CCHMapClusterControllerUtils.h @@ -31,11 +31,7 @@ MKMapRect CCHMapClusterControllerAlignMapRectToCellSize(MKMapRect mapRect, double cellSize); CCHMapClusterAnnotation *CCHMapClusterControllerFindVisibleAnnotation(NSSet *annotations, NSSet *visibleAnnotations); -#if TARGET_OS_IPHONE -double CCHMapClusterControllerMapLengthForLength(MKMapView *mapView, UIView *view, double length); -#else -double CCHMapClusterControllerMapLengthForLength(MKMapView *mapView, NSView *view, double length); -#endif +double CCHMapClusterControllerMapLengthForLength(MKMapView *mapView, double length); double CCHMapClusterControllerAlignMapLengthToWorldWidth(double mapLength); BOOL CCHMapClusterControllerCoordinateEqualToCoordinate(CLLocationCoordinate2D coordinate0, CLLocationCoordinate2D coordinate1); CCHMapClusterAnnotation *CCHMapClusterControllerClusterAnnotationForAnnotation(MKMapView *mapView, id annotation, MKMapRect mapRect); diff --git a/CCHMapClusterController/CCHMapClusterControllerUtils.m b/CCHMapClusterController/CCHMapClusterControllerUtils.m index f19159f..9b39b00 100644 --- a/CCHMapClusterController/CCHMapClusterControllerUtils.m +++ b/CCHMapClusterController/CCHMapClusterControllerUtils.m @@ -59,15 +59,11 @@ MKMapRect CCHMapClusterControllerAlignMapRectToCellSize(MKMapRect mapRect, doubl return nil; } -#if TARGET_OS_IPHONE -double CCHMapClusterControllerMapLengthForLength(MKMapView *mapView, UIView *view, double length) -#else -double CCHMapClusterControllerMapLengthForLength(MKMapView *mapView, NSView *view, double length) -#endif +double CCHMapClusterControllerMapLengthForLength(MKMapView *mapView, double length) { // Convert points to coordinates - CLLocationCoordinate2D leftCoordinate = [mapView convertPoint:CGPointZero toCoordinateFromView:view]; - CLLocationCoordinate2D rightCoordinate = [mapView convertPoint:CGPointMake(length, 0) toCoordinateFromView:view]; + CLLocationCoordinate2D leftCoordinate = [mapView convertPoint:CGPointZero toCoordinateFromView:mapView]; + CLLocationCoordinate2D rightCoordinate = [mapView convertPoint:CGPointMake(length, 0) toCoordinateFromView:mapView]; // Convert coordinates to map points MKMapPoint leftMapPoint = MKMapPointForCoordinate(leftCoordinate); diff --git a/CCHMapClusterController/CCHMapClusterOperation.m b/CCHMapClusterController/CCHMapClusterOperation.m index 19a722d..9e00836 100644 --- a/CCHMapClusterController/CCHMapClusterOperation.m +++ b/CCHMapClusterController/CCHMapClusterOperation.m @@ -82,7 +82,7 @@ - (instancetype)initWithMapView:(MKMapView *)mapView cellSize:(double)cellSize m + (double)cellMapSizeForCellSize:(double)cellSize withMapView:(MKMapView *)mapView { // World size is multiple of cell size so that cells wrap around at the 180th meridian - double cellMapSize = CCHMapClusterControllerMapLengthForLength(mapView, mapView.superview, cellSize); + double cellMapSize = CCHMapClusterControllerMapLengthForLength(mapView, cellSize); cellMapSize = CCHMapClusterControllerAlignMapLengthToWorldWidth(cellMapSize); return cellMapSize;