diff --git a/CCHMapClusterController/CCHMapClusterController.m b/CCHMapClusterController/CCHMapClusterController.m index d6ee90c..e57bd8e 100644 --- a/CCHMapClusterController/CCHMapClusterController.m +++ b/CCHMapClusterController/CCHMapClusterController.m @@ -217,20 +217,28 @@ - (void)updateDebugPolygonsInGridMapRect:(MKMapRect)gridMapRect withCellMapSize: } } } - - // Add polygons outlining each cell - CCHMapClusterControllerEnumerateCells(gridMapRect, cellMapSize, ^(MKMapRect cellMapRect) { - // cellMapRect.origin.x -= MKMapSizeWorld.width; // fixes issue when view port spans 180th meridian - - MKMapPoint points[4]; - points[0] = MKMapPointMake(MKMapRectGetMinX(cellMapRect), MKMapRectGetMinY(cellMapRect)); - points[1] = MKMapPointMake(MKMapRectGetMaxX(cellMapRect), MKMapRectGetMinY(cellMapRect)); - points[2] = MKMapPointMake(MKMapRectGetMaxX(cellMapRect), MKMapRectGetMaxY(cellMapRect)); - points[3] = MKMapPointMake(MKMapRectGetMinX(cellMapRect), MKMapRectGetMaxY(cellMapRect)); - CCHMapClusterControllerDebugPolygon *debugPolygon = (CCHMapClusterControllerDebugPolygon *)[CCHMapClusterControllerDebugPolygon polygonWithPoints:points count:4]; - debugPolygon.mapClusterController = self; - [mapView addOverlay:debugPolygon]; - }); + + int yCells = ceil((MKMapRectGetHeight(gridMapRect) + 0.1)/cellMapSize); + int xCells = ceil((MKMapRectGetWidth(gridMapRect) + 0.1)/cellMapSize); + MKMapPoint points[yCells * 3 + 1 + xCells * 3 + 1]; + int pointCount = 0; + points[pointCount++] = MKMapPointMake(MKMapRectGetMinX(gridMapRect), MKMapRectGetMinY(gridMapRect)); + for (double x = MKMapRectGetMinX(gridMapRect); x <= MKMapRectGetMaxX(gridMapRect)+0.1; x += cellMapSize) { + points[pointCount++] = MKMapPointMake(x, MKMapRectGetMinY(gridMapRect)); + points[pointCount++] = MKMapPointMake(x, MKMapRectGetMaxY(gridMapRect)); + points[pointCount++] = MKMapPointMake(x, MKMapRectGetMinY(gridMapRect)); + } + + points[pointCount++] = MKMapPointMake(MKMapRectGetMinX(gridMapRect), MKMapRectGetMinY(gridMapRect)); + for (double y = MKMapRectGetMinY(gridMapRect); y <= MKMapRectGetMaxY(gridMapRect)+0.1; y += cellMapSize) { + points[pointCount++] = MKMapPointMake(MKMapRectGetMinX(gridMapRect), y); + points[pointCount++] = MKMapPointMake(MKMapRectGetMaxX(gridMapRect), y); + points[pointCount++] = MKMapPointMake(MKMapRectGetMinX(gridMapRect), y); + } + + CCHMapClusterControllerDebugPolygon *debugPolygon = (CCHMapClusterControllerDebugPolygon *)[CCHMapClusterControllerDebugPolygon polygonWithPoints:points count:pointCount]; + debugPolygon.mapClusterController = self; + [mapView addOverlay:debugPolygon]; } - (void)deselectAllAnnotations diff --git a/CCHMapClusterController/CCHMapClusterControllerUtils.m b/CCHMapClusterController/CCHMapClusterControllerUtils.m index f19159f..bad02b3 100644 --- a/CCHMapClusterController/CCHMapClusterControllerUtils.m +++ b/CCHMapClusterController/CCHMapClusterControllerUtils.m @@ -43,6 +43,11 @@ MKMapRect CCHMapClusterControllerAlignMapRectToCellSize(MKMapRect mapRect, doubl double endX = ceil(MKMapRectGetMaxX(mapRect) / cellSize) * cellSize; double endY = ceil(MKMapRectGetMaxY(mapRect) / cellSize) * cellSize; + if (startX >= MKMapSizeWorld.width) { + startX -= MKMapSizeWorld.width; + endX -= MKMapSizeWorld.width; + } + return MKMapRectMake(startX, startY, endX - startX, endY - startY); } @@ -321,4 +326,4 @@ BOOL CCHMapClusterControllerIsUniqueLocation(NSSet *annotations) } return (geohash != nil); -} \ No newline at end of file +} diff --git a/CCHMapClusterController/CCHMapViewDelegateProxy.m b/CCHMapClusterController/CCHMapViewDelegateProxy.m index c57956c..be8516d 100644 --- a/CCHMapClusterController/CCHMapViewDelegateProxy.m +++ b/CCHMapClusterController/CCHMapViewDelegateProxy.m @@ -137,6 +137,26 @@ - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)ov return view; } + +- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id)overlay +{ + MKOverlayRenderer *renderer; + + // Target can override return value + if ([self.target respondsToSelector:@selector(mapView:rendererForOverlay:)]) { + renderer = [self.target mapView:mapView rendererForOverlay:overlay]; + } + + // Default return value for debug polygons + if (renderer == nil && [overlay isKindOfClass:CCHMapClusterControllerDebugPolygon.class]) { + MKPolygonRenderer *polygonRenderer = [[MKPolygonRenderer alloc] initWithPolygon:(MKPolygon *)overlay]; + polygonRenderer.strokeColor = [UIColor.blueColor colorWithAlphaComponent:0.7]; + polygonRenderer.lineWidth = 1; + renderer = polygonRenderer; + } + + return renderer; +} #else - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id)overlay {