Add way to track drawn Markers on map and delete/move them. Delete not implemented for BasicDrawing.

This commit is contained in:
Holt59 2018-02-25 12:10:59 +01:00
parent a9ab69965e
commit 481e30e80c
4 changed files with 93 additions and 12 deletions

View file

@ -36,6 +36,35 @@ public class BasicDrawing extends JPanel implements Drawing {
*/ */
private static final long serialVersionUID = 96779785877771827L; private static final long serialVersionUID = 96779785877771827L;
public class BasicMarkerTracker implements MarkerTracker {
// Point of the marker.
private Point point;
// Color of the "marker".
private Color color;
public BasicMarkerTracker(Point point, Color color) {
this.point = point;
this.color = color;
}
@Override
public Point getPoint() {
return point;
}
@Override
public void moveTo(Point point) {
BasicDrawing.this.drawMarker(point, color);
}
@Override
public void delete() {
}
};
// Default path color. // Default path color.
public static final Color DEFAULT_PATH_COLOR = new Color(255, 0, 255); public static final Color DEFAULT_PATH_COLOR = new Color(255, 0, 255);
@ -215,14 +244,15 @@ public class BasicDrawing extends JPanel implements Drawing {
} }
@Override @Override
public void drawMarker(Point point) { public MarkerTracker drawMarker(Point point) {
drawPoint(point, DEFAULT_MARKER_WIDTH, this.gr.getColor()); drawPoint(point, DEFAULT_MARKER_WIDTH, this.gr.getColor());
return new BasicMarkerTracker(point, this.gr.getColor());
} }
@Override @Override
public void drawMarker(Point point, Color color) { public MarkerTracker drawMarker(Point point, Color color) {
setColor(color); setColor(color);
drawMarker(point); return drawMarker(point);
} }
@Override @Override

View file

@ -61,14 +61,14 @@ public interface Drawing {
* *
* @param point * @param point
*/ */
public void drawMarker(Point point); public MarkerTracker drawMarker(Point point);
/** /**
* Draw the given point with the given color. * Draw the given point with the given color.
* *
* @param point * @param point
*/ */
public void drawMarker(Point point, Color color); public MarkerTracker drawMarker(Point point, Color color);
/** /**
* Draw a point width the given width and color. Do not use this to mark * Draw a point width the given width and color. Do not use this to mark
@ -100,8 +100,7 @@ public interface Drawing {
* *
* @param path * @param path
* @param color * @param color
* @param markers * @param markers Show origin and destination markers.
* Show origin and destination markers.
*/ */
public void drawPath(Path path, Color color, boolean markers); public void drawPath(Path path, Color color, boolean markers);
@ -118,8 +117,7 @@ public interface Drawing {
* *
* *
* @param path * @param path
* @param markers * @param markers Show origin and destination markers.
* Show origin and destination markers.
*/ */
public void drawPath(Path path, boolean markers); public void drawPath(Path path, boolean markers);

View file

@ -45,6 +45,36 @@ public class MapViewDrawing extends MapView implements Drawing {
*/ */
private static final long serialVersionUID = 8606967833704938092L; private static final long serialVersionUID = 8606967833704938092L;
public class MapViewMarkerTracker implements MarkerTracker {
// Marker associated.
private Marker marker;
public MapViewMarkerTracker(Marker marker) {
this.marker = marker;
}
@Override
public Point getPoint() {
return new Point(marker.getLatLong().getLongitude(), marker.getLatLong().getLatitude());
}
@Override
public void moveTo(Point point) {
this.delete();
Marker marker = new Marker(convertPoint(point), this.marker.getBitmap(), this.marker.getHorizontalOffset(),
this.marker.getVerticalOffset());
this.marker = marker;
MapViewDrawing.this.getLayerManager().getLayers().add(this.marker);
}
@Override
public void delete() {
MapViewDrawing.this.getLayerManager().getLayers().remove(marker);
}
};
// Default path color. // Default path color.
public static final Color DEFAULT_PATH_COLOR = new Color(66, 134, 244); public static final Color DEFAULT_PATH_COLOR = new Color(66, 134, 244);
@ -160,15 +190,16 @@ public class MapViewDrawing extends MapView implements Drawing {
} }
@Override @Override
public void drawMarker(Point point) { public MarkerTracker drawMarker(Point point) {
drawMarker(point, Color.GREEN); return drawMarker(point, Color.GREEN);
} }
@Override @Override
public void drawMarker(Point point, Color color) { public MarkerTracker drawMarker(Point point, Color color) {
Bitmap bitmap = MarkerUtils.getMarkerForColor(color); Bitmap bitmap = MarkerUtils.getMarkerForColor(color);
Marker marker = new Marker(convertPoint(point), bitmap, 0, -bitmap.getHeight() / 2); Marker marker = new Marker(convertPoint(point), bitmap, 0, -bitmap.getHeight() / 2);
getLayerManager().getLayers().add(marker); getLayerManager().getLayers().add(marker);
return new MapViewMarkerTracker(marker);
} }
@Override @Override

View file

@ -0,0 +1,22 @@
package org.insa.graphics.drawing;
import org.insa.graph.Point;
public interface MarkerTracker {
/**
* @return The point associated with this marker.
*/
public Point getPoint();
/**
*
*/
public void moveTo(Point point);
/**
* Delete this marker.
*/
public void delete();
}