Android的 - 绘制路径覆盖的图形页面 [英] Android - drawing path as overlay on MapView
问题描述
我有一个延伸覆盖和implemments Overlay.Snappable中的一类。我已经重写了画方式:
I have a class that extends Overlay and implemments Overlay.Snappable. I have overriden its draw method:
@Override
public void draw(Canvas canvas, MapView mv, boolean shadow)
{
Projection projection = mv.getProjection();
ArrayList<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
//Creating geopoints - ommited for readability
Path p = new Path();
for (int i = 0; i < geoPoints.size(); i++) {
if (i == geoPoints.size() - 1) {
break;
}
Point from = new Point();
Point to = new Point();
projection.toPixels(geoPoints.get(i), from);
projection.toPixels(geoPoints.get(i + 1), to);
p.moveTo(from.x, from.y);
p.lineTo(to.x, to.y);
}
Paint mPaint = new Paint();
mPaint.setStyle(Style.FILL);
mPaint.setColor(0xFFFF0000);
mPaint.setAntiAlias(true);
canvas.drawPath(p, mPaint);
super.draw(canvas, mv, shadow);
}
正如你所看到的,我让地图上的点的名单,我想他们形成一个多边形。
As you can see, I make a list of points on a map and I want them to form a polygonal shape.
现在的问题是,当我设置绘图方式进行填充或FILL_AND_STROKE没有显示在屏幕上,但是当我将其设置为刚刚中风,并设置描边宽度,它acctually画什么是应该吸取
Now, the problem is that when I set paint style to be FILL or FILL_AND_STROKE nothing shows up on the screen, but when I set it to be just stroke, and set stroke width, it acctually draws what it is supposed to draw.
现在,我寻找解决办法,但没有出现。你能告诉我,如果我错过了一些东西在$ C $来设置C本身,还是有上覆盖帆布绘画时某些种类的限制?
Now, I looked for solution, but nothing comes up. Can you tell me if I something missed to set in the code itself, or are there some sorts of constraints when drawing on Overlay canvases?
感谢
推荐答案
几件事情。您应该使用 p.moveTo(from.x,from.y);
只有一次,即,当你想要做的第一次首次
A few things. You should use p.moveTo(from.x, from.y);
only once i.e., first time when you want to do it for the first time.
试试这个设置属性为油漆
对象用于绘制多边形。
Try this to set attributes for the paint
object used for painting the polygon.
polygonPaint = new Paint();
polygonPaint.setStrokeWidth(2);
polygonPaint.setStyle(Paint.Style.STROKE);
polygonPaint.setAntiAlias(true);
希望这有助于。
Hope this helps.
这篇关于Android的 - 绘制路径覆盖的图形页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!