带有Retina-Tiles的MKTileOverlay [英] MKTileOverlay with Retina-Tiles

查看:336
本文介绍了带有Retina-Tiles的MKTileOverlay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MKMapKit中加载512x512px图块有问题。
服务器提供512x512 .jpeg磁贴。

I have issues to load 512x512px tiles in MKMapKit. The Server provides 512x512 .jpeg tiles.

我在MKMapView中找不到自定义视网膜磁贴的任何解决方案或示例实现。

I could not find any solution or sample implementation for custom retina tiles in MKMapView.

我做什么:

当我用

 overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
 overlay.tileSize = CGSizeMake(512.0f, 512.0f);
 [_mapView insertOverlay:overlay atIndex:MAP_OVERLAY_INDEX_TILE level:MKOverlayLevelAboveLabels];

...瓷砖缩放正确但只加载了一半(不仅在视觉上 - 我嗅探了请求并且瓷砖丢失了)

… tiles are scaling correct but only half of them is loaded (not only visually - i sniffed the requests and the tiles are missing)

 overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
 overlay.tileSize = CGSizeMake(256.0f, 256.0f);
 [_mapView insertOverlay:overlay atIndex:MAP_OVERLAY_INDEX_TILE level:MKOverlayLevelAboveLabels];

...显示所有图块但缩放不正确

… all tiles are displayed but scaling incorrect

这是我的绘图方法:

(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
    MKOverlayRenderer *overlayRenderer = nil;

    if([overlay isKindOfClass:MKTileOverlay.class])
    {
        overlayRenderer = [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
    }

    return overlayRenderer;
}

... overlayRenderer.contentScaleFactor总是1 ...无论是什么tileSize(iOS模拟器) 7.1视网膜)

… the overlayRenderer.contentScaleFactor is always 1 … no matter what tileSize (iOS simulator 7.1 retina)

有任何建议吗?

致以诚挚的问候,Steve

Best regards, Steve

推荐答案

以下代码仅适用于iOS 7(不是iOS 8)。
覆盖MKTileOverlayRenderer。平铺大小设置为256.

The following code works only on iOS 7 (not iOS 8). Override MKTileOverlayRenderer. Tile size is set to 256.

@implementation FKDTileOverlayRenderer
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
    CGFloat scale = [[UIScreen mainScreen] scale];
    if (scale > 1.0)
    {
        CGSize tileSize = ((MKTileOverlay*)self.overlay).tileSize;
        CGRect rect = [self rectForMapRect:mapRect];

        CGContextSaveGState(context);
        CGAffineTransform t = CGContextGetCTM(context);
        CGContextConcatCTM(context, CGAffineTransformInvert(t));
        double ratio = tileSize.width/(rect.size.width*2);

        CGContextTranslateCTM(context, (double)(-rect.origin.x)*ratio, tileSize.height+ratio*(double)rect.origin.y);
        CGContextScaleCTM(context, ratio, -ratio);

        [super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
        CGContextRestoreGState(context);
    }
    else
        [super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
}
@end

在地图视图控制器中:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
    if ([overlay isKindOfClass:[MKTileOverlay class]]) 
    {
        return [[FKDTileOverlayRenderer alloc] initWithTileOverlay:overlay];
    }
    return nil;
}

这篇关于带有Retina-Tiles的MKTileOverlay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆