开发者

Custom tile based map is slow

I am working on a map for my public transit app. I'm using SurfaceView, it's a tile based map, there are 2 threads besides the main thread - drawing thread and bitmap loading thread.

Bitmaps are 256x256 PNGs stored on the SD card, I am caching the loaded bitmaps, cache capacity is 64 bitmaps. There are different sets of bitmaps for every zoom level, my map has 4 zoom levels, every next level is 2x more zoomed.

Unfortunately scrolling and pinch zooming is not smooth on my Nexus One, FPS is 15 - 20. When no tiles are being loaded FPS is 35 - 40. If I lower priority of the bitmap loading thread, it becomes completely smooth but I often see not yet loaded (white) tiles on the map - which is even worse than the non-smoothness.

So what could I do? I have 2 ideas so far:

  • Try OpenGL, but I don't want to spend time on it and then find out it my FPS only inreased by 3. Also I want to show popups (that scroll with the map) after user clicks on map markers, which I don't know how to do in GLSurfaceView.
  • Set low priority to bitmap loading thread only when user touches the screen or when there's an ongoing animation. I t开发者_如何学编程ried that but for unknown reason it seemed to even worsen the problem a little bit, touching / not touching the screen didn't have any effect. If it was just some bug I can fix, there's still another problem. If I use kinetic scroll to quickly move the map, I will see many not cached bitmaps.


Don't do any I/O on your rendering thread. (How can you be using GLSurfaceView and not using OpenGL by the way?)

I have written an OpenGL tile-based map view and it is smooth as butter on a Nexus One (not measured the fps but it's easily as smooth as the maps app on an iPhone 4). The trick is to move all I/O off the rendering thread, lower the priorities of your worker threads, and to immediately requestRender() at the end of the current render if you know another's going to be needed (such as during a pan or zoom), i.e. don't wait for that to be signalled by another thread. Look for Yell.com in the Market to see it in action (may be UK-only though).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜