【问题标题】:Break up MKMap into tiles -- tiles too small将 MKMap 分解为图块——图块太小
【发布时间】:2013-06-12 09:21:25
【问题描述】:

我正在使用MKOverlayMKOverlayViewMKMapView 制作叠加层。首先,我只想根据当前的缩放级别将世界划分为图块。因此,当我缩小时,我只想拥有 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。

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

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

【问题讨论】:

    标签: ios objective-c mkmapview mapkit


    【解决方案1】:

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

    【讨论】:

    • 谢谢,这是一个非常好的主意,我会改成那个。但这不能解决我现在的问题吧?
    • 嗯,我不知道为什么,但是在我改变了平铺之后,事情看起来和预期的一样。这对我来说毫无意义,但我不会抱怨;)。
    【解决方案2】:

    您可能需要查看http://tilemill.com,以更轻松地为此类事情平铺内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多