根据 MapKit 缩放级别调整自定义 MKAnnotationView 的大小

发布于 2024-10-04 16:37:03 字数 382 浏览 6 评论 0原文

情况如下: 我使用自定义注释在地图上显示图像。一切工作正常,但我想通过调整 AnnotationView 的大小,使其随着地图缩小而缩小来在视觉上改进它。我想这样做是因为,显然,更多注释会填满屏幕,需要缩小,以便它们不会彼此重叠太多,并且用户可以看到更多注释。 (当然,我想在地图再次放大时放大AnnotationViews)。

我通过从地图中删除所有注释并在调用 RegionDidChangeAnimated 时再次将它们添加回来来实现此目的。然而,这些图像是从互联网加载的,因此再次下载图像(因为注释已被删除)似乎没有意义。

我希望我已经很好地解释了情况,并希望将来能为 SO 做出贡献。

提前致谢。

PS 我正在使用 iOS 4.0 进行开发

Here is the situation:
I am displaying images on the map by using custom annotations. Everything works fine but I would like to improve it visually by resizing the AnnotationView so that it shrinks as the map is zoomed out. I want to do this because, obviously, more annotations fill up the screen and need to be shrunk so that they don't overlap each other too much and the user can see more annotations. (Of course, I would like to enlarge AnnotationViews when the map is zoomed in again).

I have achieved this by removing all annotations from the map and adding them back again, whenever regionDidChangeAnimated is called. However, these images are loaded from the internet, so downloading the images again (since the annotations have been removed) doesn't seem to make sense.

I hope I have explained the situation well, and hope to contribute to SO in the future.

Thanks in advance.

P.S. I'm developing with iOS 4.0

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

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

发布评论

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

评论(2

無心 2024-10-11 16:37:03

由于您使用的是 iOS 4.0,我建议使用符合 MKOverlay 协议的类,而不是 MKAnnotationView。与地图叠加缩放并适当缩放。您或许可以使用 1 个覆盖层来处理所有注释。查看 Apple 在 2010 年 WWDC 演讲中提供的 HazardMap 演示,网址为 http://developer.apple.com

或者,您也可以可以使用类似 k 最近邻算法的算法来按缩放比例对注释进行分组。但是,如果您有很多注释,这可能会有点慢。我用数千个注释尝试过一次,但不喜欢由此带来的性能损失。我认为<不过,使用此方法 1000 个注释可能会有不错的性能。

Since you are using iOS 4.0 I would suggest using a class that conforms to the MKOverlay protocol instead of MKAnnotationView. Overlays zoom with the map and will scale appropriately. You can probably use 1 overlay to handle all your annotations. Check out the HazardMap demo Apple provided in the 2010 WWDC talks on http://developer.apple.com

Alternatively, you could use something like the k nearest neighbors algorithm to group annotations per zoom scale. However, that can be kind of slow if you have a lot of annotations. I tried it once with several thousand annotations and did not like the performance hit that was incurred. I think < 1000 annotations might have decent performance with this method though.

山川志 2024-10-11 16:37:03

听起来您已经走在正确的道路上,唯一真正的问题是图像的下载。当您收到它们并在显示它们之前先查看它们时,是否有任何特殊原因无法通过将它们写入文档目录(或缓存目录,如果您希望它们在应用程序退出时消失)来缓存它们?

It sounds like you're already on the right path and that the only real problem is the downloading of the images. Is there any particular reason you can't cache them by writing them to the documents directory (or the cache directory if you want them to go way when the app quits) when you receive them and look there first before displaying them?

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