0

我正在研究MKMapView使用MKOverlayand的叠加层MKOverlayView。首先,我只想根据当前的缩放级别将世界划分为图块。因此,当我缩小时,我只想拥有 1 个大图块,下一个缩放级别为 4 个图块,然后是 9 个等。这是有效的。现在我的问题:

在 zoomLevel 3 上,图块之间开始出现间隙。这不会发生在只有 4 个 Tiles 的缩放级别 2 上,而是在每个后​​续缩放级别中发生。

 _ _ _
|1 2 3|
|4 5 6| <-- Tiles
|7_8_9|

这两个图像分别显示了瓷砖 1、2、4、5 和 5、6、8、9。

在此处输入图像描述 在此处输入图像描述

正如您所看到的,每个瓷砖后间隙都会增加。现在到我的代码:

绘制地图矩形:

- (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);
}

获取矩形映射点:

- (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;
}
4

2 回答 2

1

平铺的常见方式是将每个平铺分成4个。所以顶层有1个平铺。把它切成4层,你就有了下一层。将这些中的每一个切成 4 层,你就有了下一层,等等。这样,任何层上的瓦片都可以很容易地计算出它上面或下面的瓦片的边界,如果一个层的数据还没有准备好它可以使用上面图块的一部分,或者加入下面的四个图块并使用它。

于 2013-06-12T09:44:58.563 回答
0

您可能想查看http://tilemill.com以获得更简单的方法来平铺此类内容的内容。

于 2013-06-13T22:29:25.477 回答