From 6ea197245a8772368b710b842a875cb11bc7b9d9 Mon Sep 17 00:00:00 2001 From: Tommaso Madonia Date: Thu, 26 Feb 2015 01:59:12 +0800 Subject: [PATCH 1/4] Fix debug grid (#30) --- CCHMapClusterController/CCHMapClusterController.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CCHMapClusterController/CCHMapClusterController.m b/CCHMapClusterController/CCHMapClusterController.m index d6ee90c..36bfc1b 100644 --- a/CCHMapClusterController/CCHMapClusterController.m +++ b/CCHMapClusterController/CCHMapClusterController.m @@ -220,12 +220,10 @@ - (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[1] = MKMapPointMake(MKMapRectGetMaxX(cellMapRect) + MKMapSizeWorld.width, MKMapRectGetMinY(cellMapRect)); + points[2] = MKMapPointMake(MKMapRectGetMaxX(cellMapRect) + MKMapSizeWorld.width, MKMapRectGetMaxY(cellMapRect)); points[3] = MKMapPointMake(MKMapRectGetMinX(cellMapRect), MKMapRectGetMaxY(cellMapRect)); CCHMapClusterControllerDebugPolygon *debugPolygon = (CCHMapClusterControllerDebugPolygon *)[CCHMapClusterControllerDebugPolygon polygonWithPoints:points count:4]; debugPolygon.mapClusterController = self; From 530ffa2e48bd77ae8a89c3e673a3c5958201745b Mon Sep 17 00:00:00 2001 From: Tommaso Madonia Date: Fri, 27 Feb 2015 09:58:13 +0800 Subject: [PATCH 2/4] Map rect alignment fix --- CCHMapClusterController/CCHMapClusterControllerUtils.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 +} From 96a3f316f19380d4512b6dce53fee60caffff169 Mon Sep 17 00:00:00 2001 From: Tommaso Madonia Date: Fri, 27 Feb 2015 10:00:21 +0800 Subject: [PATCH 3/4] New debug polygon overlay --- .../CCHMapClusterController.m | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/CCHMapClusterController/CCHMapClusterController.m b/CCHMapClusterController/CCHMapClusterController.m index 36bfc1b..e57bd8e 100644 --- a/CCHMapClusterController/CCHMapClusterController.m +++ b/CCHMapClusterController/CCHMapClusterController.m @@ -217,18 +217,28 @@ - (void)updateDebugPolygonsInGridMapRect:(MKMapRect)gridMapRect withCellMapSize: } } } - - // Add polygons outlining each cell - CCHMapClusterControllerEnumerateCells(gridMapRect, cellMapSize, ^(MKMapRect cellMapRect) { - MKMapPoint points[4]; - points[0] = MKMapPointMake(MKMapRectGetMinX(cellMapRect), MKMapRectGetMinY(cellMapRect)); - points[1] = MKMapPointMake(MKMapRectGetMaxX(cellMapRect) + MKMapSizeWorld.width, MKMapRectGetMinY(cellMapRect)); - points[2] = MKMapPointMake(MKMapRectGetMaxX(cellMapRect) + MKMapSizeWorld.width, 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 From d7f012c33b4b96b566e19c94e633a18d90d5d432 Mon Sep 17 00:00:00 2001 From: Tommaso Madonia Date: Fri, 27 Feb 2015 10:14:50 +0800 Subject: [PATCH 4/4] iOS implementation of mapView:rendererForOverlay: --- .../CCHMapViewDelegateProxy.m | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 {