2012-04-05 4 views
2

Android에서 게임을 만들고있어 Google지도 창에서 영역 또는 폴리곤을 오버레이해야합니다.Google지도에서 드로잉 폴리곤 사용 문제

class polygonOverlay extends Overlay { 
    //this is the array of vertices we need to draw 
    GeoPoint[] vet; 
    Point[] points; 
    private float[] fVet; 
    //get the vertices 

    public polygonOverlay(GeoPoint[] v) { 
     vet = v; 
     points = new Point[v.length]; 
     fVet = new float[(v.length)*2]; 

    } 

    //this is how we draw it. 
    @Override 
    public void draw(Canvas canvas, MapView mapv, boolean shadow) { 

     super.draw(canvas,mapv, shadow); 

     //do some things 
     //set all the points to a point. 
     for(int i = 0; i < points.length; i++) { 
      points[i] = new Point(); 
     } 

     //convert from the array of geoPoints to the array of points using the projection. 
     for(int i = 0; i < vet.length; i++){ 
     projection.toPixels(vet[i], points[i]); 

     } 

     //convert the point to the float array 
     for(int i = 0; i < points.length; i++) { 
     fVet[2*i] = points[i].x; 
     fVet[(2*i)+1] = points[i].y; 
     } 
     //things be done... 

     //create a array of int colors. 
     int[] colorArray = new int[points.length]; 

     for(int i = 0; i < points.length; i++) { 
      colorArray[i] = Color.RED; 
     } 

     //if we are drawing a shadow, then dont draw anything 
     Paint mPaint = new Paint(); 
     mPaint.setDither(true); 
     mPaint.setColor(Color.RED); 
     mPaint.setStyle(Paint.Style.FILL_AND_STROKE); 
     mPaint.setStrokeJoin(Paint.Join.ROUND); 
     mPaint.setStrokeCap(Paint.Cap.ROUND); 
     mPaint.setStrokeWidth(4); 
     //lets draw some things. 
     canvas.drawLine(points[1].x, points[1].y, 200, 200, mPaint); 
     canvas.drawVertices(
       Canvas.VertexMode.TRIANGLES, 
       fVet.length, 
       fVet, 
       0, 
       null, 
       0, 
       colorArray, 
       0, 
       null, 
       0, 
       0, 
       mPaint 
       ); 


    } 

} 

문제는 다각형이 표시되지 않습니다하지만입니다 :

지금까지 난 다음 만들었습니다. 나는 모든 것을 시험해 보았고, 지난 밤 2am까지 그렇게했다. 그러나 그것은 단지 작동하지 않을 것이다.

내가 생각하기 시작하고있어 자사 내 전화하지 내 코드 ...

사람이 내가 잘못 한 일을 볼 수 있습니까?

+0

캔버스에서 간단한 것을 그리기 시작 했습니까? – Benoir

+0

옙, 나는 선을 그었다. 그 drawVertices는 작동하지 않습니다 –

답변

1

다각형 생성은 간단

Paint mPaint = new Paint(); 
mPaint.setStrokeWidth(2); //2 pixel line width 
mPaint.setColor(0xFF097286); //tealish with no transparency 
mPaint.setStyle(Paint.Style.STROKE); //stroked, aka a line with no fill 
mPaint.setAntiAlias(true); // no jagged edges, etc 

그럼으로 경로 그릴 :

첫째는 페인트 오브젝트 정의 여기

yourCanvas.drawPath(path,mPaint); 

및된다지도 오버레이 링크 : android maps circle overlay, dynamically change radius?

+0

그릴 경로로 다각형을 그릴 수 있습니까? –

+1

네, 왜 .. !!! 이 링크 참조 http://stackoverflow.com/questions/3501126/how-to-draw-a-filled-triangle-in-android-canvas – Nimit

0

bug in the drawVertices method이 있으며가 필요합니다.은 코드에서 fVet 배열과 동일한 크기 여야합니다.
참고 : 첫 번째 fVet/2 색만이 실제로 그리기에 사용되며 나머지는 무시됩니다.

관련 문제