2

I've set of n points and I want to draw a n-sided polygon using these points.

I tried using android.graphics.path (please see below).

Path path = new Path();
Vertex currVtx;

for (int j = 0; j < vertices.size(); j++) {
 currVtx = vertices.get(j);

 if (!currVtx.hasLatLong())
  continue;

 Point currentScreenPoint = getScreenPointFromGeoPoint(
   currVtx, mapview);
 if (j == 0)
  path.moveTo(currentScreenPoint.x, currentScreenPoint.y); 
          // vertex.
 else
  path.lineTo(currentScreenPoint.x, currentScreenPoint.y);

}

Currently I'm getting a solid (filled with the color of the canvas) polygon with this code. Is there a way that I can get an unfilled polygon. There is an alternative to android.graphics.Path

Thanks.

Soumya Simanta
  • 11,523
  • 24
  • 106
  • 161
  • Hi! Can you explain how you implemented getScreenPointFromGeoPoint please? I am trying to draw a filled polygon, but I don't knwo how the get the screen point from the lat and long I have. If you can share that I woud be greatful – marimaf Nov 08 '11 at 21:20

1 Answers1

8

Define a Paint object:

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.

Then draw the path with:

yourCanvas.drawPath(path,mPaint);

You can look up the paint documentation but there are tons of options to control how its drawn.

Mark
  • 2,932
  • 18
  • 15