0

マップポイント間に線を引くためのこのコードがあります

@Override
public void draw(Canvas canvas, MapView mapview, boolean shadow) {

    if (!shadow) {
        Projection projection = mapview.getProjection();

        for(int i=0; i< puntos.size()-1; i++) {

            Point origen = new Point();
            Point destino = new Point();

            projection.toPixels(puntos.get(i).getPoint(), origen);
            projection.toPixels(puntos.get(i+1).getPoint(), destino);

            Paint paint = new Paint();

            paint.setStyle(Style.STROKE);
            paint.setStrokeWidth(5);
            paint.setColor(Color.GREEN);
            paint.setAntiAlias(true);

            canvas.drawLine(origen.x, origen.y, destino.x, destino.y, paint);
            mapview.invalidate();
        }
    }
super.draw(canvas, mapview, shadow);
}

しかし、マップ内のポイントを近すぎたり、ラインが他のラインと交差するポイントに配置すると、マップビューは近くのポイントに複数のラインを描画します。したがって、ポイント1、2、3、4がある場合、ポイント1にはポイント2、3、4へのドローラインがあります

これを解決する方法はありますか??

4

2 に答える 2

0

次のコードを変更します。

@Override 
public void draw(Canvas canvas, MapView mapview, boolean shadow) { 

if (!shadow) { 
    if(puntos.size() == 0) return;

    //initialization
    Point origen = new Point(); 
    Point destino = new Point(); 


    Paint paint = new Paint(); 

    paint.setStyle(Style.STROKE); 
    paint.setStrokeWidth(5); 
    paint.setColor(Color.GREEN); 
    paint.setAntiAlias(true); 

    //end of initialization

    Projection projection = mapview.getProjection(); 
    projection.toPixels(puntos.get(0).getPoint(), origen); 

    for(int i=1; i< puntos.size(); i++) { 
        projection.toPixels(puntos.get(i).getPoint(), destino); 
        canvas.drawLine(origen.x, origen.y, destino.x, destino.y, paint); 
    } 
} 
super.draw(canvas, mapview, shadow); 
}

理想的には、上記の初期化ブロック内のコードをオーバーレイコンストラクターに移動し、オブジェクトorigenとグローバルを作成する必要がdestinoあります。paintそうすることで、メモリ使用率が向上し、オーバーレイの存続期間中、各オブジェクトが1つだけ作成されます。

幸運を。

于 2012-10-11T12:42:30.623 に答える
0

以下のコードを試してください。また、図形を色で塗りつぶします。その機能は省略できます。

        Paint mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setStyle(Style.FILL_AND_STROKE);
        mPaint.setColor(Color.RED);
        mPaint.setAlpha(9);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);

        Path path = new Path();

        Projection projection = mapView.getProjection();

        for(int j = 0; j < geoArrayist.size(); j++) 
        {
            Iterator<GeoPoint> it = geoArrayist.iterator();
            while(it.hasNext()) 
            {
                GeoPoint arrayListGeoPoint = it.next();

                Point currentScreenPoint = new Point();
                projection.toPixels(arrayListGeoPoint, currentScreenPoint);

                if(j == 0)
                    path.moveTo(currentScreenPoint.x, currentScreenPoint.y); 
                else
                    path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
            }                 
        }
        canvas.drawPath(path, mPaint);
于 2012-10-10T11:28:23.473 に答える