私の問題は、より高いレベルにズームすると、描画された領域が消えることです。
トピックのフォローアップになります: ズームインすると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);
}
}