防止缩放时覆盖消失 - MKMapView & MK叠加

发布于 2024-10-05 14:06:28 字数 532 浏览 0 评论 0原文

我正在开发一个 iPhone / iPad 应用程序,该应用程序通过 MKMapView 和 MKOverlay 使用半透明平铺地图叠加。

我希望用户能够深度放大地图,但我的地图叠加层的分辨率仅达到 6 级。

我不想限制缩放。

但是...如果用户缩放“太远”,然后滚动到新图块,如果它们缩放得比覆盖图块树更深,则不会绘制我的覆盖图。

我希望即使用户放大时也能绘制叠加层。

是否有任何最佳实践可以实现这一目标?

我提出了两个选项:

1)设置用户可以缩放的距离限制。并不理想,因为即使覆盖层是低分辨率的,它们也可能仍在透明度的颜色范围内,并且透明覆盖层看似消失会产生误导。

2) 预渲染图块比其他方式更深得多...这可行,但它使我的应用程序的大小增加了一个数量级。

必须有更好的方法。有什么想法吗???

更新:我能找到的与我正在做的最接近的示例代码是来自 WWDC 2010 的 Apple 的 TileMap 示例。他们的代码也遇到同样的问题 - 如果放大“太远”,则不会显示地图叠加层。

I am working on an iPhone / iPad app that is using semi-transparant tiled map overlays via MKMapView and MKOverlay.

I want users to be able to zoom in deeply into the maps, but the resolution of my map overlays only goes to level 6.

I do not want to limit zooming.

But... If a user zooms "too far" and then scrolls to a new tile, if they are zoomed deeper than the tree of overlay tiles, my overlay is not drawn.

I want the overlay to draw even when the user is zoomed in deep.

Are there any best practices to achieve this?

The two options I have come up with:

1) Set a limit on how far users can zoom. Not ideal because even if the overlay is low-res, they are likely still within the colored range of transparency, and having the transparent over-layer seemingly vanish is misleading.

2) Pre-render tiles that go way deeper than they otherwise would... This works, but it balloons my app by an order of magnitude in size.

There has got to be a better way. Any ideas???

UPDATE: The closest example code to what I am doing I can find is Apple's TileMap sample from WWDC 2010. Their code suffers from the same problem - if you are zoomed in "too far" the map overlay is not displayed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的奇迹 2024-10-12 14:06:28

MKTileOverlay 有一个 MaximumZ 属性。对我来说,我的图块服务器仅渲染到缩放18(来自osm数据的mapnik),所以我设置了overlay.maximumZ = 18,现在当我放大到19或20(iPhone上的最高)时,它只是保持缩放18 块瓷砖。

也就是说,我正在通过 initWithURLTemplate 初始化我的覆盖层:

在 viewDidLoad 中(或在初始化覆盖层的任何位置):

self.mapView.delegate = self;
NSString *urlTemplate = @"http://servername/osm/{z}/{x}/{y}.png";
self.mapOverlay = [[MKTileOverlay alloc] initWithURLTemplate:urlTemplate];
self.mapOverlay.canReplaceMapContent=YES;
[self.map addOverlay:self.overlay level:MKOverlayLevelAboveLabels];

然后实现以下方法:

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {    
    if([overlay isKindOfClass:[MKTileOverlay class]]) {
        MKTileOverlay *tileOverlay = (MKTileOverlay *)overlay;
        tileOverlay.maximumZ = 18;  // This is what sets the cap, zoom levels further in will not be rendered and instead will keep previous zoom level tiles.
        MKTileOverlayRenderer *renderer = [[MKTileOverlayRenderer alloc] initWithTileOverlay:tileOverlay];
        return renderer;
    }
    return nil;
}

MKTileOverlay has a maximumZ property. For me, my tile server only rendered up to zoom 18 (mapnik from osm data), so I set my overlay.maximumZ = 18, and now when I zoom in to 19 or 20 (highest on iPhone), it just keeps the zoom 18 tiles.

That said I am initializing my overlay via initWithURLTemplate:

In viewDidLoad (or wherever you initialize your overlay):

self.mapView.delegate = self;
NSString *urlTemplate = @"http://servername/osm/{z}/{x}/{y}.png";
self.mapOverlay = [[MKTileOverlay alloc] initWithURLTemplate:urlTemplate];
self.mapOverlay.canReplaceMapContent=YES;
[self.map addOverlay:self.overlay level:MKOverlayLevelAboveLabels];

Then implment the following method:

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {    
    if([overlay isKindOfClass:[MKTileOverlay class]]) {
        MKTileOverlay *tileOverlay = (MKTileOverlay *)overlay;
        tileOverlay.maximumZ = 18;  // This is what sets the cap, zoom levels further in will not be rendered and instead will keep previous zoom level tiles.
        MKTileOverlayRenderer *renderer = [[MKTileOverlayRenderer alloc] initWithTileOverlay:tileOverlay];
        return renderer;
    }
    return nil;
}
手心的海 2024-10-12 14:06:28

我修改了 Apple 的 TileMap 示例代码,添加了“OverZoom”模式。我已经发布了更多详细信息和我的代码作为 这个问题

我希望我可以帮助其他遇到这个问题的人。

I modified Apple's TileMap sample code by adding an "OverZoom" mode. I have posted more details and my code as an answer to this question.

I hope I can help out anyone else who stumbles across this problem.

春夜浅 2024-10-12 14:06:28

我建议查看 HazardMap 示例代码...这是一个很好的示例,说明如何使用平铺的 MKOverlay 支持各个级别的缩放。

I recommend checking out the HazardMap sample code on Apple's site... it's a great example of how to support zooming at all levels with a tiled MKOverlay.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文