Я создал класс, расширяющий класс Overlay для создания изогнутой линии.При первом использовании все работает нормально, но когда я пытаюсь нарисовать вторую кривую линию, карта содержит метод draw и не позволяет мне рисовать что-либо еще.Я хотел бы рисовать отдельную фигуру при каждом нажатии кнопки
private void drawCurvedLine() {
OsmCurvedLine osmCurvedLine = new OsmCurvedLine(c);
osmCurvedLine.setFillColour(ShapeColour.getInstance(c).defaultPinColour());
osmCurvedLine.setBorderColour(ShapeColour.getInstance(c).paintBorderColour());
map.getMapView().getOverlays().add(osmCurvedLine);
osmCurvedLine.setEditMode(true);
}
.
public class OsmCurvedLine extends Overlay {
private boolean editMode = false;
private float x1, y1;
private GeoPoint p1 = null, p2 = null;
private Context c;
private Paint fillColour, borderColour;
private ArrayList<GeoPoint> geoPoints = new ArrayList<>();
public OsmCurvedLine(Context context) {
this.c = context;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Point screenPts1 = new Point();
Point screenPts2 = new Point();
Point screenPts3 = new Point();
// draw dot on first point
if (p1 != null) {
mapView.getProjection().toPixels(p1, screenPts1);
canvas.drawCircle(screenPts1.x, screenPts1.y, 20, getFillColour());
}
for (int i = 0; i < geoPoints.size(); i++) {
mapView.getProjection().toPixels(geoPoints.get(i), screenPts2);
mapView.getProjection().toPixels(geoPoints.get(i + 1), screenPts3);
canvas.drawLine(screenPts2.x, screenPts2.y, screenPts3.x, screenPts3.y, getBorderColour());
}
}
@Override
public boolean onSingleTapUp(MotionEvent e, MapView mapView) {
if (editMode) {
x1 = e.getX();
y1 = e.getY();
if (p1 == null) {
p1 = (GeoPoint) mapView.getProjection().fromPixels((int) x1, (int) y1);
}
p2 = (GeoPoint) mapView.getProjection().fromPixels((int) x1, (int) y1);
geoPoints.add(p2);
mapView.invalidate();
return true;
}
return false;
}
//getters setters
}