我的问题是,当我放大到更高级别时,绘图填充区域消失了。
这将是一个非常跟进的话题: Android MapView 覆盖在放大时消失
上面的链接解决了我画线的问题,但填充区域仍然存在同样的问题。
我也需要帮助来解决填充区域。
我当前的代码如下:
class MyOverlay extends Overlay {
private final List<GeoPoint> points;
private int oldX;
private int oldY;
public MyOverlay(List<GeoPoint> points) {
this.points = points;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
int x1 = -1;
int y1 = -1;
int x2 = -1;
int y2 = -1;
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GREEN);
paint.setStrokeWidth(5);
int size = points.size();
for (int i = 0; i <= size; i++) {
Point point = new Point();
mapView.getProjection().toPixels(points.get(i % size),
point);
x2 = point.x;
y2 = point.y;
if (i > 0) {
canvas.drawLine(x1, y1, x2, y2, paint);
}
x1 = x2;
y1 = y2;
}
//the following are drawing the filled area
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.FILL);
paint.setAlpha(60);
Projection projection = mapView.getProjection();
Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();
projection.toPixels(gpoint1, p1);
projection.toPixels(gpoint2, p2);
projection.toPixels(gpoint3, p3);
Path path = new Path();
path.moveTo(p1.x, p1.y);
path.lineTo(p2.x, p2.y);
path.lineTo(p3.x, p3.y);
canvas.drawPath(path, paint);
}
}