我可以使用singleTapConfirmedHelper()
制作多边形。但我还是有问题。添加第四个点(红色圆圈)时如何删除线条(蓝色箭头)。添加第四个点后,该线不会消失。我希望我解释得很好。谢谢。
@Override
public boolean singleTapConfirmedHelper(GeoPoint p) {
Polygon circle = new Polygon();
circle.setPoints(Polygon.pointsAsCircle(p, 2.0));
circle.setFillColor(0x12121212);
circle.setStrokeColor(Color.RED);
circle.setStrokeWidth(2);
map.getOverlays().add(circle);
circle.setInfoWindow(new
BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble,
map));
circle.setTitle("Centered on " + p.getLatitude() + "," +
p.getLongitude());
List<GeoPoint> pts = new ArrayList<>();
pts.add(new GeoPoint(p.getLatitude(), p.getLongitude()));
Polygon polygon = new Polygon(ctx);
polygon.setTitle("This is a polygon");
polygon.setSubDescription(Polygon.class.getCanonicalName());
polygon.setFillColor(0x12121212);
polygon.setVisible(true);
polygon.setStrokeColor(Color.BLACK);
polygon.setStrokeWidth(4);
polygon.setInfoWindow(new
BasicInfoWindow(R.layout.bonuspack_bubble, map));
polygon.setPoints(pts);
map.getOverlays().add(polygon);
map.invalidate();
return true;
}
答案 0 :(得分:1)
您为每个添加的点绘制新的多边形,而不是删除旧的多边形。因此,MapView将把它们全部绘制在另一个上面。在调用map.invalidate()之前,您应该从叠加列表中删除先前绘制的多边形。
Polygon polygon = new Polygon(ctx);
polygon.setTitle("This is a polygon");
polygon.setSubDescription(Polygon.class.getCanonicalName());
polygon.setFillColor(0x12121212);
polygon.setVisible(true);
polygon.setStrokeColor(Color.BLACK);
polygon.setStrokeWidth(4);
polygon.setInfoWindow(new
BasicInfoWindow(R.layout.bonuspack_bubble, map));
polygon.setPoints(pts);
map.getOverlays().add(polygon);
if (oldPolygon != null) {
map.getOverlays().remove(oldPolygon);
}
oldPolygon = polygon;
map.invalidate();