diff options
| author | Konrad Gräfe <konradgraefe@aol.com> | 2015-01-26 22:53:38 +0100 |
|---|---|---|
| committer | rsudev <rasch@munin-soft.de> | 2015-02-09 23:12:25 +0100 |
| commit | 5d3018c77573e4cacc795284139c260ea70aa8a0 (patch) | |
| tree | 8094929bf0a6c77b6b165aac2ee1b7ec9f1d03f3 /main/src/cgeo | |
| parent | 8fbaa36d29ea1934a48f51039bb60eaa1df3f010 (diff) | |
| download | cgeo-5d3018c77573e4cacc795284139c260ea70aa8a0.zip cgeo-5d3018c77573e4cacc795284139c260ea70aa8a0.tar.gz cgeo-5d3018c77573e4cacc795284139c260ea70aa8a0.tar.bz2 | |
Add line between curren location and destination to the map view
Diffstat (limited to 'main/src/cgeo')
9 files changed, 287 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 4724566..afbc1ed 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -141,6 +141,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private CachesOverlay overlayCaches; private PositionAndScaleOverlay overlayPositionAndScale; private DistanceOverlay overlayDistance; + private DirectionOverlay overlayDirection; final private GeoDirHandler geoDirUpdate = new UpdateLoc(this); private SearchResult searchIntent = null; @@ -450,6 +451,11 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapView.clearOverlays(); overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker)); + + if (coordsIntent != null || geocodeIntent != null) { + overlayDirection = mapView.createAddDirectionOverlay(coordsIntent, geocodeIntent); + } + overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(); if (trailHistory != null) { overlayPositionAndScale.setHistory(trailHistory); @@ -1005,6 +1011,11 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } if (needsRepaintForDistanceOrAccuracy || needsRepaintForHeading) { + if (map.overlayDirection != null) { + map.overlayDirection.setCoordinates(currentLocation); + map.mapView.repaintRequired(map.overlayDirection); + } + map.overlayPositionAndScale.setCoordinates(currentLocation); map.overlayPositionAndScale.setHeading(currentHeading); map.mapView.repaintRequired(map.overlayPositionAndScale); diff --git a/main/src/cgeo/geocaching/maps/DirectionOverlay.java b/main/src/cgeo/geocaching/maps/DirectionOverlay.java new file mode 100755 index 0000000..0807afa --- /dev/null +++ b/main/src/cgeo/geocaching/maps/DirectionOverlay.java @@ -0,0 +1,83 @@ +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.MapItemFactory; +import cgeo.geocaching.maps.interfaces.MapProjectionImpl; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; +import cgeo.geocaching.settings.Settings; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; +import android.location.Location; + +public class DirectionOverlay implements GeneralOverlay { + private Geopoint currentCoords; + private final Geopoint destinationCoords; + private final MapItemFactory mapItemFactory; + + private OverlayImpl ovlImpl = null; + + private Paint line = null; + + public DirectionOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, final Geopoint coords, final String geocode) { + this.ovlImpl = ovlImpl; + + if (coords == null) { + final Viewport bounds = DataStore.getBounds(geocode); + if (bounds == null) { + this.destinationCoords = new Geopoint(0, 0); + } else { + this.destinationCoords = bounds.center; + } + } else { + this.destinationCoords = coords; + } + + this.mapItemFactory = Settings.getMapProvider().getMapItemFactory(); + } + + public void setCoordinates(final Location coordinatesIn) { + currentCoords = new Geopoint(coordinatesIn); + } + + @Override + public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { + drawInternal(canvas, mapView.getMapProjection()); + } + + @Override + public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, final MapProjectionImpl projection, final byte drawZoomLevel) { + drawInternal(canvas, projection); + } + + private void drawInternal(final Canvas canvas, final MapProjectionImpl projection) { + if (currentCoords == null) { + return; + } + + if (line == null) { + line = new Paint(); + line.setAntiAlias(true); + line.setStrokeWidth(2f); + line.setColor(0xFFEB391E); + } + + final Point pos = new Point(); + final Point dest = new Point(); + projection.toPixels(mapItemFactory.getGeoPointBase(currentCoords), pos); + projection.toPixels(mapItemFactory.getGeoPointBase(destinationCoords), dest); + + canvas.drawLine(pos.x, pos.y, dest.x, dest.y, line); + } + + @Override + public OverlayImpl getOverlayImpl() { + return this.ovlImpl; + } + +} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java new file mode 100755 index 0000000..cc896c6 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java @@ -0,0 +1,53 @@ +package cgeo.geocaching.maps.google.v1; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DirectionOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import com.google.android.maps.MapView; +import com.google.android.maps.Overlay; + +import android.graphics.Canvas; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class GoogleDirectionOverlay extends Overlay implements OverlayImpl { + + private final DirectionOverlay overlayBase; + private final Lock lock = new ReentrantLock(); + + public GoogleDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DirectionOverlay(this, mapView, coords, geocode); + } + + @Override + public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { + super.draw(canvas, mapView, shadow); + + assert mapView instanceof MapViewImpl; + overlayBase.draw(canvas, (MapViewImpl) mapView, shadow); + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + } + + @Override + public void unlock() { + lock.unlock(); + } + + @Override + public MapViewImpl getMapViewImpl() { + throw new UnsupportedOperationException(); + } + +} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java index 08c9ae7..9664c3e 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java @@ -5,6 +5,7 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; @@ -136,6 +137,13 @@ public class GoogleMapView extends MapView implements MapViewImpl { } @Override + public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { + final GoogleDirectionOverlay ovl = new GoogleDirectionOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DirectionOverlay) ovl.getBase(); + } + + @Override public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { final GoogleDistanceOverlay ovl = new GoogleDistanceOverlay(this, coords, geocode); getOverlays().add(ovl); diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java index 00a8790..f15f12a 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java @@ -3,6 +3,7 @@ package cgeo.geocaching.maps.interfaces; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; @@ -52,6 +53,8 @@ public interface MapViewImpl { DistanceOverlay createAddDistanceOverlay(Geopoint coords, String geocode); + DirectionOverlay createAddDirectionOverlay(Geopoint coords, String geocode); + void setMapSource(); /** diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java new file mode 100755 index 0000000..98c19db --- /dev/null +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java @@ -0,0 +1,56 @@ +package cgeo.geocaching.maps.mapsforge; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DirectionOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import org.mapsforge.android.maps.Projection; +import org.mapsforge.android.maps.overlay.Overlay; + +import android.graphics.Canvas; +import android.graphics.Point; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class MapsforgeDirectionOverlay extends Overlay implements OverlayImpl { + + private DirectionOverlay overlayBase = null; + private final Lock lock = new ReentrantLock(); + + public MapsforgeDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DirectionOverlay(this, mapView, coords, geocode); + } + + @Override + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { + + if (overlayBase != null) { + overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); + } + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + } + + @Override + public void unlock() { + lock.unlock(); + + } + + @Override + public MapViewImpl getMapViewImpl() { + return (MapViewImpl) internalMapView; + } + +} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index dd67a8f..a81c108 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -4,6 +4,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; @@ -120,6 +121,13 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override + public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { + final MapsforgeDirectionOverlay ovl = new MapsforgeDirectionOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DirectionOverlay) ovl.getBase(); + } + + @Override public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); getOverlays().add(ovl); diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java new file mode 100755 index 0000000..281b27f --- /dev/null +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java @@ -0,0 +1,57 @@ +package cgeo.geocaching.maps.mapsforge.v024; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DirectionOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import org.mapsforge.android.mapsold.Overlay; +import org.mapsforge.android.mapsold.Projection; + +import android.graphics.Canvas; +import android.graphics.Point; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class MapsforgeDirectionOverlay extends Overlay implements OverlayImpl { + + private DirectionOverlay overlayBase = null; + private final Lock lock = new ReentrantLock(); + + public MapsforgeDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DirectionOverlay(this, mapView, coords, geocode); + } + + @Override + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { + + if (overlayBase != null) { + overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); + } + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + + } + + @Override + public void unlock() { + lock.unlock(); + + } + + @Override + public MapViewImpl getMapViewImpl() { + return (MapViewImpl) internalMapView; + } + +} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 6b97707..937c13b 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -4,6 +4,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; @@ -111,6 +112,13 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override + public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { + final MapsforgeDirectionOverlay ovl = new MapsforgeDirectionOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DirectionOverlay) ovl.getBase(); + } + + @Override public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); getOverlays().add(ovl); |
