views:

12

answers:

0

I use following code to draw a track on the mapview, but i find that the bitmap only cache the mapview size. if some line outside the map. the bitmap will not cache.

That make the track not complete.

how can i solve that problem? Thank you

`if ((bmap == null) || (lastZoom != mapv.getZoomLevel())) {

Projection proj = mapv.getProjection();

// store zoom level for comparing in the next onDraw
lastZoom = mapv.getZoomLevel();

// draw a path of all of the points in my route
GeoPoint start = routePoints.get(0);
Point startPt = new Point();            
proj.toPixels(start, startPt);

Path path = new Path();
path.moveTo(startPt.x, startPt.y);

Point nxtPt;

for (GeoPoint nextPoint : routePoints) 
{
    nxtPt = new Point();
    proj.toPixels(nextPoint, nxtPt);
    path.lineTo(nxtPt.x, nxtPt.y);
}

// create a new bitmap, the size of the map view
bmap = Bitmap.createBitmap(mapv.getWidth(), mapv.getHeight(), Bitmap.Config.ARGB_8888);

// create an off-screen canvas to prepare new bitmap, and draw path on to it
Canvas offscreencanvas = new Canvas(bmap);
offscreencanvas.drawPath(path, mPaint);

// draw the bitmap of the path onto my map view's canvas
canvas.drawBitmap(bmap, 0, 0, null);

// make a note of where we put the bitmap, so we know how much we 
//  we need to move it by if the user pans the map
mapStartPosition = proj.fromPixels(0, 0);

} else { // as we're in onDraw, we think the user has panned/moved the map // if we're in here, the zoom level hasn't changed, and // we've already got a bitmap with a drawing of the route path

Projection proj = mapv.getProjection();

// where has the mapview been panned to?
Point offsetPt = new Point();
proj.toPixels(mapStartPosition, offsetPt);

// draw the bitmap in the new correct location
canvas.drawBitmap(bmap, offsetPt.x, offsetPt.y, null);

}`