开发者

How to store canvas line in activity?

I'm trying to draw a line on canvas and project it into a map in android. I'm also using tabs for my app. When I'm flipping around tabs back and forward I'm losing the lines I drew. Is there a way to store them somehow so they will stay there all the time? MyLocationOverlay class looks like this:

class MyLocationOverlay extends Overlay 
{

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
    {

    super.draw(canvas, mapView, shadow);

    Paint paint = new Paint();

    paint.setStrokeWidth(2);
    paint.setARGB(255, 153, 29, 29);
    paint.setStyle(Paint.Style.STROKE);

    if(controlPoints>0)
    {

        Point point1_returned = new Point();        
        Point point2_returned = new Point();    
        Point point3_returned = new Point();

        mapView.getProjection().toPixels(returned_pin1_geo, point1_returned);
        mapView.getProjection().toPixels(returned_pin2_geo, point2_returned);
        mapView.getProjection().toPixels(returned_pin3_geo, point3_returned);

        canvas.drawLine(point1_returned.x, point1_returned.y, point2_returned.x, point2_returned.y, paint);
        canvas.drawLine(point2_returned.x, point2_returned.y, point3_returned.x, point3_returned.y, paint);
        canvas.drawLine(point3_returned.x, point3_returned.y, point1_returned.x, point1_returned.y, paint);

        return true;
    } 

    else

    {
        //Point lastPoint = new Point();
        Point point = new Point();      
        // Converts lat/lng-Point to OUR coordinates on the screen.
        Point myScreenCoords = new Point();     
        Point thirdPoint = new Point();

        mapView.getProjection().toPixels(pin1_geo, myScreenCoords);
        mapView.getProjection().toPixels(pin2_geo, point);
        mapView.getProjection().toPixels(pin3_geo, thirdPoint);
        canvas.drawLine(myScreenCoords.x, myScreenCoords.y, point.x, point.y, paint);
        canvas.drawLine(point.x, point.y, thirdPoint.x, thirdPoint.y, paint);
        canvas.drawLine(thirdPoint.x, thirdPoint.y, myScreenCoords.x, myScreenCoords.y, paint);
        return true;
    }







    /*canvas.drawLine(point1.x, point1.y, point2.x, point2.y, paint);
    canvas.drawLine(point2.x, point2.y, point3.x, poin开发者_JAVA技巧t3.y, paint);
    canvas.drawLine(point3.x, point3.y, point1.x, point1.y, paint);*/



 } 

}

Can someone help me with this? I already tried flagging the tab etc. but nothing worked. Help greatly appreciated!


try out this post, I once had the same problem ;-)

How to display a route between two geocoords in google maps?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜