From 481e30e80cf5d8cba9ed66105dd057ee27ae7683 Mon Sep 17 00:00:00 2001 From: Holt59 Date: Sun, 25 Feb 2018 12:10:59 +0100 Subject: [PATCH] Add way to track drawn Markers on map and delete/move them. Delete not implemented for BasicDrawing. --- .../insa/graphics/drawing/BasicDrawing.java | 36 ++++++++++++++++-- .../org/insa/graphics/drawing/Drawing.java | 10 ++--- .../insa/graphics/drawing/MapViewDrawing.java | 37 +++++++++++++++++-- .../insa/graphics/drawing/MarkerTracker.java | 22 +++++++++++ 4 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 src/main/org/insa/graphics/drawing/MarkerTracker.java diff --git a/src/main/org/insa/graphics/drawing/BasicDrawing.java b/src/main/org/insa/graphics/drawing/BasicDrawing.java index 9082908..89574fa 100644 --- a/src/main/org/insa/graphics/drawing/BasicDrawing.java +++ b/src/main/org/insa/graphics/drawing/BasicDrawing.java @@ -36,6 +36,35 @@ public class BasicDrawing extends JPanel implements Drawing { */ 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. public static final Color DEFAULT_PATH_COLOR = new Color(255, 0, 255); @@ -215,14 +244,15 @@ public class BasicDrawing extends JPanel implements Drawing { } @Override - public void drawMarker(Point point) { + public MarkerTracker drawMarker(Point point) { drawPoint(point, DEFAULT_MARKER_WIDTH, this.gr.getColor()); + return new BasicMarkerTracker(point, this.gr.getColor()); } @Override - public void drawMarker(Point point, Color color) { + public MarkerTracker drawMarker(Point point, Color color) { setColor(color); - drawMarker(point); + return drawMarker(point); } @Override diff --git a/src/main/org/insa/graphics/drawing/Drawing.java b/src/main/org/insa/graphics/drawing/Drawing.java index 2bb21d8..45dc04b 100644 --- a/src/main/org/insa/graphics/drawing/Drawing.java +++ b/src/main/org/insa/graphics/drawing/Drawing.java @@ -61,14 +61,14 @@ public interface Drawing { * * @param point */ - public void drawMarker(Point point); + public MarkerTracker drawMarker(Point point); /** * Draw the given point with the given color. * * @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 @@ -100,8 +100,7 @@ public interface Drawing { * * @param path * @param color - * @param markers - * Show origin and destination markers. + * @param markers Show origin and destination markers. */ public void drawPath(Path path, Color color, boolean markers); @@ -118,8 +117,7 @@ public interface Drawing { * * * @param path - * @param markers - * Show origin and destination markers. + * @param markers Show origin and destination markers. */ public void drawPath(Path path, boolean markers); diff --git a/src/main/org/insa/graphics/drawing/MapViewDrawing.java b/src/main/org/insa/graphics/drawing/MapViewDrawing.java index 5656e4f..5f7ca1f 100644 --- a/src/main/org/insa/graphics/drawing/MapViewDrawing.java +++ b/src/main/org/insa/graphics/drawing/MapViewDrawing.java @@ -45,6 +45,36 @@ public class MapViewDrawing extends MapView implements Drawing { */ 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. public static final Color DEFAULT_PATH_COLOR = new Color(66, 134, 244); @@ -160,15 +190,16 @@ public class MapViewDrawing extends MapView implements Drawing { } @Override - public void drawMarker(Point point) { - drawMarker(point, Color.GREEN); + public MarkerTracker drawMarker(Point point) { + return drawMarker(point, Color.GREEN); } @Override - public void drawMarker(Point point, Color color) { + public MarkerTracker drawMarker(Point point, Color color) { Bitmap bitmap = MarkerUtils.getMarkerForColor(color); Marker marker = new Marker(convertPoint(point), bitmap, 0, -bitmap.getHeight() / 2); getLayerManager().getLayers().add(marker); + return new MapViewMarkerTracker(marker); } @Override diff --git a/src/main/org/insa/graphics/drawing/MarkerTracker.java b/src/main/org/insa/graphics/drawing/MarkerTracker.java new file mode 100644 index 0000000..b137a86 --- /dev/null +++ b/src/main/org/insa/graphics/drawing/MarkerTracker.java @@ -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(); + +}