diff options
Diffstat (limited to 'main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java')
-rw-r--r-- | main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java index 63fcd73..9a6e4b9 100644 --- a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java +++ b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java @@ -1,5 +1,8 @@ package cgeo.geocaching.maps; +import cgeo.geocaching.DataStore; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -16,22 +19,40 @@ public class PositionAndScaleOverlay implements GeneralOverlay { PositionDrawer positionDrawer = null; ScaleDrawer scaleDrawer = null; + DirectionDrawer directionDrawer = null; + DistanceDrawer distanceDrawer = null; - public PositionAndScaleOverlay(OverlayImpl ovlImpl) { + public PositionAndScaleOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, final Geopoint coords, final String geocode) { this.ovlImpl = ovlImpl; positionDrawer = new PositionDrawer(); scaleDrawer = new ScaleDrawer(); + + if (coords != null) { + directionDrawer = new DirectionDrawer(coords); + distanceDrawer = new DistanceDrawer(mapView, coords); + } else if (geocode != null) { + final Viewport bounds = DataStore.getBounds(geocode); + if (bounds != null) { + directionDrawer = new DirectionDrawer(bounds.center); + distanceDrawer = new DistanceDrawer(mapView, bounds.center); + } + } } - public void setCoordinates(Location coordinatesIn) { + public void setCoordinates(final Location coordinatesIn) { positionDrawer.setCoordinates(coordinatesIn); + if (directionDrawer != null) { + directionDrawer.setCoordinates(coordinatesIn); + distanceDrawer.setCoordinates(coordinatesIn); + } + } public Location getCoordinates() { return positionDrawer.getCoordinates(); } - public void setHeading(float bearingNow) { + public void setHeading(final float bearingNow) { positionDrawer.setHeading(bearingNow); } @@ -40,21 +61,27 @@ public class PositionAndScaleOverlay implements GeneralOverlay { } @Override - public void drawOverlayBitmap(Canvas canvas, Point drawPosition, - MapProjectionImpl projection, byte drawZoomLevel) { + public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final MapProjectionImpl projection, final byte drawZoomLevel) { drawInternal(canvas, projection, getOverlayImpl().getMapViewImpl()); } @Override - public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) { + public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { drawInternal(canvas, mapView.getMapProjection(), mapView); } - private void drawInternal(Canvas canvas, MapProjectionImpl projection, MapViewImpl mapView) { + private void drawInternal(final Canvas canvas, final MapProjectionImpl projection, final MapViewImpl mapView) { + if (directionDrawer != null) { + directionDrawer.drawDirection(canvas, projection); + } positionDrawer.drawPosition(canvas, projection); scaleDrawer.drawScale(canvas, mapView); + if (distanceDrawer != null) { + distanceDrawer.drawDistance(canvas); + } } @Override @@ -66,7 +93,7 @@ public class PositionAndScaleOverlay implements GeneralOverlay { return positionDrawer.getHistory(); } - public void setHistory(ArrayList<Location> history) { + public void setHistory(final ArrayList<Location> history) { positionDrawer.setHistory(history); } } |