How to make route drawing more efficient?

后端 未结 3 785
夕颜
夕颜 2021-01-01 05:50

This is the code I\'m using to draw route. When i have 1000 of points, route severely slows ui. Maybe someone could provide a code snippet or a link which explains how to do

3条回答
  •  梦谈多话
    2021-01-01 06:04

    You can draw the path to a transparent Bitmap object (whatever size you see fitting - the bigger it is, the better the detail of the path yet higher memory consumption).

    Make sure you create it with Bitmap.config.ARGB_8888 for transparency.

    Once you've done this, you'll be using two rectangles to display the path on the Overlay:

    • A source rectangle to determine which part of the path is visible
    • A destination rectangle to determine where you want to display this piece of the path on the Overlay's canvas.

    You'll be using Canvas.drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)

    Shouldn't be too difficult, you've done most of the important calculations in your transformPath method.

    Added:

    You can actually do a combination of both holding a path drawn to a Bitmap and redrawing the actual path points. Use the technique described above for when the user moves around the map or zooms in/out then redraw the path when the user lets go of the screen.

提交回复
热议问题