【问题标题】:Drawing an empty polygon given a set of points on a Map Overylay (Android 2.1)给定地图叠加层上的一组点绘制一个空多边形(Android 2.1)
【发布时间】:2011-02-18 09:28:36
【问题描述】:

我已经设置了n 点,我想使用这些点绘制一个n-sided 多边形。

我尝试使用 android.graphics.path(请参见下文)。

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);

}

目前,我正在使用此代码获得一个实心(填充画布颜色)多边形。有没有办法可以得到一个未填充的多边形。 android.graphics.Path有一个替代方法

谢谢。

【问题讨论】:

  • 嗨!你能解释一下你是如何实现 getScreenPointFromGeoPoint 的吗?我正在尝试绘制一个填充的多边形,但我不知道如何从我拥有的纬度和经度中获取屏幕点。如果你能分享我会很高兴

标签: android graphics path polygon android-sdk-2.1


【解决方案1】:

定义一个Paint对象:

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);

您可以查看绘图文档,但有很多选项可以控制其绘制方式。

【讨论】:

  • 如何在我的地图视图上绘制画布?
猜你喜欢
  • 1970-01-01
  • 2016-10-28
  • 1970-01-01
  • 2012-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-30
相关资源
最近更新 更多