我正在使用MKOverlay
和MKOverlayView
覆蓋MKMapView
。要開始的事情,我只是想根據當前縮放級別將世界劃分爲瓦片。所以當我縮小時,我只想要一個大的瓷磚,下一個縮放級別4的瓷磚,然後是9等。這是工作。現在到我的問題:將MKMap分解成瓷磚 - 瓷磚太小
在zoomLevel 3,瓷磚之間開始有差距。這在縮放級別2上不會發生,只有4個圖塊,但在每個縮放級別中都是如此。
3210這兩幅圖分別顯示了瓷磚1,2,4,5和5,6,8,9。
正如你可以看到每塊的後間隙增大。現在,我的代碼:
drawMapRect:
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
NSUInteger zoomLevel = [self zoomLevelForZoomScale:zoomScale];
HeatMap *heatMap = (HeatMap *)self.overlay;
HeatMapTileManager *tileManager = [heatMap getHeatMapTileManagerForZoomLevel:zoomLevel];
MKMapRect mapTile = [tileManager getRectForMapPoint:mapRect.origin atZoomLevel:zoomLevel];
CGContextSetAlpha(context, 0.5);
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGColorRef color = CGColorCreate(rgb, (CGFloat[]){ .745, .941, .467, 1 });
CGContextSetFillColorWithColor(context, color);
CGRect mapTileCGRect = [self rectForMapRect:mapTile];
CGContextFillRect(context, mapTileCGRect);
}
getRectForMapPoint:
- (MKMapRect) getRectForMapPoint:(MKMapPoint)mapPoint
atZoomLevel:(NSInteger)level
{
double stepSize = MKMapSizeWorld.width/(double)level;
double rectIDx = floor(mapPoint.x/stepSize);
double rectIDy = floor(mapPoint.y/stepSize);
MKMapRect mapRect = MKMapRectMake(stepSize * rectIDx,
stepSize * rectIDy,
stepSize,
stepSize);
NSLog(@"X: %f, Width: %f", mapRect.origin.x, stepSize);
NSLog(@"Y: %f, Height: %f", mapRect.origin.y, stepSize);
return mapRect;
}
謝謝,這是一個非常好的主意,我會改變這一點。但那現在不能解決我的問題嗎? – imbaer
嗯,我不知道爲什麼,但是在我改變了平鋪之後,事情看起來和預期的一樣。這對我來說沒有意義,但我不會抱怨;)。 – imbaer