ItemizedOverlay.draw() 的性能问题
我有一个类:
public class WaypointOverlay extends ItemizedOverlay<OverlayItem>
它重写了 ItemizedOverlay
的 draw()
方法。
在我的活动中,我有一张包含许多覆盖项目和列表的地图。我从 Traceviewer 输出和 logcat 中注意到,即使地图未受影响,MapView.onDraw()
也会被多次调用。这导致列表和地图确实没有响应(当我的 WaypointOverlay
类只是从这些 onDraw
调用返回时,一切都表现良好)
我怎样才能拥有 onDraw
调用发生的频率较低 - 理想情况下仅当 MapView
更改范围时?我尝试在 onDraw 中检查 MapView 是否具有与上次 onDraw 调用中相同的纬度/经度跨度,并且仅绘制如果两者不同。这导致 OverlayItems
仅在地图平移或缩放时出现。
关于提高性能有什么想法吗?
I have a class:
public class WaypointOverlay extends ItemizedOverlay<OverlayItem>
It overrides the draw()
method of the ItemizedOverlay
.
In my Activity, I have a map with many overlay items as well as a list. I noticed from traceviewer output and logcat that MapView.onDraw()
was being called many times even when the map goes untouched. This resulted in a really unresponsive list and map (when I have my WaypointOverlay
class simply return from these onDraw
calls, everything performs well)
How can I have the onDraw
calls happen less frequently - ideally only when the MapView
changes span? I tried, in onDraw
, checking if the MapView
has the same lat/lon span as it did in the last onDraw
call, and only drawing if the two are different. This caused the OverlayItems
to only appear when the map was panning or zooming.
Any ideas on improving performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我可能已经解决了这个问题(至少对于我来说)。在我的应用程序中,用户可以离开地图然后返回到地图,所有这些都在同一个活动中进行。每次用户返回地图时,我都会重新添加我创建的所有叠加层。这意味着地图上有太多的叠加层 - 我看不到它们,因为它们重叠了。调用 MapView.getOverlays().clear() 使地图和列表的性能显着提高。
I think I may have solved this problem (for my case, at least). In my app, the user can navigate away from the map and then return to it, all in the same activity. Every time the user returned to the map, I re-added all the overlays I had created. This meant that way too many overlays were on the map - I couldn't see them because they overlapped. Calling MapView.getOverlays().clear() has made the map and list perform substantially better.