使用CATiledLayer的drawLayer:inContext:
我正在尝试使用 CATiledLayer
+ UIScrollView
来实现我自己的地图引擎。
在我的实现的 drawLayer:inContext:
方法中,如果我有当前边界框所需的某个图块图像,我会立即在上下文中绘制它。
但是,当我在本地缓存数据结构中没有可用的数据时,图块图像将从图块服务器异步请求/下载,并且不会在上下文中绘制任何内容。
问题是,当我不在上下文中绘制任何内容时,视图的该部分显示为空白图块。预期的行为是显示先前缩放级别的放大平铺视图。
如果你们遇到过类似的问题并找到了解决方案,请告诉我。
I am trying to implement my own map engine by using CATiledLayer
+ UIScrollView
.
In drawLayer:inContext:
method of my implementation, if I have a certain tile image needed for the current bounding box, I immediately draw it in the context.
However, when I do not have one available in the local cache data structure, the tile image is asynchronously requested/downloaded from a tile server, and not draw anything in the context.
The problem is, when I don't draw anything in the context, that part of the view is shown as a blank tile. And the expected behavior is to show the zoom-in scaled tile view from the previous zoom level.
If you guys have faced any similar problem and found any solution for this, please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一旦获得数据,您就必须为图块设置 setNeedsDisplayInRect: 。在图块可用之前,您必须忍受它是空白的,因为您无法影响 CATiledLayer 正在创建哪些图块。
You have to setNeedsDisplayInRect: for the tile as soon as you have the data. You have to live with it being blank until the tile is available because you have no way to affect which tiles CATiledLayer is creating.
我也做了同样的事情,阻塞线程直到图块下载完成。性能不错,运行流畅。我使用队列来存储每个图块请求,因此我还可以取消那些不再有用的图块请求。
为此,请在启动异步图块请求后立即使用锁来停止线程,并在缓存图块后立即将其解锁。
你听起来不错吗?这对我有用!
I do the same, blocking the thread until the tile has been downloaded. The performance is good, it runs smoothly. I'm using a queue to store every tile request, so I can also cancel those tile requests that are not useful anymore.
To do so, use a lock to stop the thread just after you launch your async tile request, and unlock it as soon as you have your tile cached.
Sounds that good to you? It worked for me!
您的
CATiledLayer
应该按照您的预期提供之前缩放级别的图块。平铺图层的levelsOfDetail
和levelsOfDetailBias
设置为多少?Your
CATiledLayer
should be providing this tile from the previous zoom level as you expect. What are yourlevelsOfDetail
andlevelsOfDetailBias
set to for the tiled layer?您必须调用 setNeedsDisplay 或 setNeedsDisplayInRect: 但问题是,如果您调用此方法,那么它将重绘滚动视图中的每个图块。因此,尝试使用 UIView 的子类而不是 CATiledLayer 子类,并像这样实现 TiledView (UIView 的子类),
对于
滚动视图,
You have to call setNeedsDisplay or setNeedsDisplayInRect: But the problem is if you call this then it will redraw every tile in the scrollView. So try using subclass of UIView instead of CATiledLayer subclass, and implement TiledView (subclass of UIView) like this,
and
for scrollView,