Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions CCHMapClusterController/CCHMapClusterController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion CCHMapClusterController/CCHMapClusterControllerUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -321,4 +326,4 @@ BOOL CCHMapClusterControllerIsUniqueLocation(NSSet *annotations)
}

return (geohash != nil);
}
}
20 changes: 20 additions & 0 deletions CCHMapClusterController/CCHMapViewDelegateProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)ov

return view;
}

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)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<MKOverlay>)overlay
{
Expand Down