Add possibility to show/hide a marker after its creation without having to delete/recreate it.
This commit is contained in:
parent
9ae576a058
commit
422a3267ca
@ -46,9 +46,13 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
// Image of the marker
|
// Image of the marker
|
||||||
protected BufferedImage image;
|
protected BufferedImage image;
|
||||||
|
|
||||||
|
// Visible?
|
||||||
|
protected boolean visible;
|
||||||
|
|
||||||
public BasicMarkerTracker(Point point, BufferedImage image) {
|
public BasicMarkerTracker(Point point, BufferedImage image) {
|
||||||
this.point = point;
|
this.point = point;
|
||||||
this.image = image;
|
this.image = image;
|
||||||
|
this.visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,6 +66,12 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
BasicDrawing.this.repaint();
|
BasicDrawing.this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVisible(boolean visible) {
|
||||||
|
this.visible = visible;
|
||||||
|
BasicDrawing.this.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
BasicDrawing.this.markers.remove(this);
|
BasicDrawing.this.markers.remove(this);
|
||||||
@ -151,10 +161,12 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
// Draw markers
|
// Draw markers
|
||||||
for (BasicMarkerTracker mtracker: markers) {
|
for (BasicMarkerTracker mtracker: markers) {
|
||||||
BufferedImage img = mtracker.image;
|
if (mtracker.visible) {
|
||||||
int px = this.projx(mtracker.getPoint().getLongitude());
|
BufferedImage img = mtracker.image;
|
||||||
int py = this.projy(mtracker.getPoint().getLatitude());
|
int px = this.projx(mtracker.getPoint().getLongitude());
|
||||||
g.drawImage(img, px - img.getWidth() / 2, py - img.getHeight(), this);
|
int py = this.projy(mtracker.getPoint().getLatitude());
|
||||||
|
g.drawImage(img, px - img.getWidth() / 2, py - img.getHeight(), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,11 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||||||
MapViewDrawing.this.getLayerManager().getLayers().add(this.marker);
|
MapViewDrawing.this.getLayerManager().getLayers().add(this.marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVisible(boolean visible) {
|
||||||
|
this.marker.setVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
MapViewDrawing.this.getLayerManager().getLayers().remove(marker);
|
MapViewDrawing.this.getLayerManager().getLayers().remove(marker);
|
||||||
|
@ -14,6 +14,13 @@ public interface MarkerTracker {
|
|||||||
*/
|
*/
|
||||||
public void moveTo(Point point);
|
public void moveTo(Point point);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show or hide this marker - A marker should be visible when created.
|
||||||
|
*
|
||||||
|
* @param visible true to show the marker, false to hide.
|
||||||
|
*/
|
||||||
|
public void setVisible(boolean visible);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete this marker.
|
* Delete this marker.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user