From d7948a7316476dc21ab80a59034df1705bf79d71 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 18 Mar 2019 15:18:16 +0200 Subject: [PATCH] Show azimuth from last point in measurement tool and in points list --- .../main/java/net/osmand/util/MapUtils.java | 23 +++++++++++++++++++ .../src/net/osmand/plus/OsmAndFormatter.java | 14 ++++++++++- .../MeasurementToolFragment.java | 5 ++-- .../measurementtool/MeasurementToolLayer.java | 6 +++-- .../adapter/MeasurementToolAdapter.java | 23 +++++++++++++++++-- 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java index 2368fef570..1241cfa3a9 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.MapObject; import net.osmand.data.QuadPoint; @@ -120,6 +121,28 @@ public class MapUtils { return getDistance(l1.getLatitude(), l1.getLongitude(), l2.getLatitude(), l2.getLongitude()); } + + public static float getBearingToPoint(double lat1, double lon1, double lat2, double lon2) { + Location l1 = new Location(""); + Location l2 = new Location(""); + l1.setLatitude(lat1); + l1.setLongitude(lon1); + l2.setLatitude(lat2); + l2.setLongitude(lon2); + return getBearingToPoint(l1, l2); + } + + public static float getBearingToPoint(Location l1, double lat, double lon) { + Location l2 = new Location(""); + l2.setLatitude(lat); + l2.setLongitude(lon); + return getBearingToPoint(l1, l2); + } + + public static float getBearingToPoint(Location l1, Location l2) { + return l1.bearingTo(l2); + } + public static double checkLongitude(double longitude) { if (longitude >= MIN_LONGITUDE && longitude <= MAX_LONGITUDE) { return longitude; diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index cd87a1e744..463f531ac1 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -3,8 +3,10 @@ package net.osmand.plus; import android.content.Context; import android.text.format.DateUtils; +import net.osmand.Location; import net.osmand.data.Amenity; import net.osmand.data.City.CityType; +import net.osmand.data.LatLon; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; @@ -165,7 +167,17 @@ public class OsmAndFormatter { return df.format(meters / mainUnitInMeters) + " " + app.getString(mainUnitStr); } - + + public static String getFormattedAzimuth(float bearing) { + int azimuth; + if (bearing < 0.0) { + azimuth = (int) (360 + bearing); + } else { + azimuth = (int) bearing; + } + return azimuth + "°"; + } + public static String getFormattedDistance(float meters, OsmandApplication ctx) { return getFormattedDistance(meters, ctx, true); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index a20bb76073..c5ce3e0a5b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -360,9 +360,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { measurementLayer.setOnMeasureDistanceToCenterListener(new MeasurementToolLayer.OnMeasureDistanceToCenter() { @Override - public void onMeasure(float distance) { + public void onMeasure(float distance, float bearing) { String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication()); - distanceToCenterTv.setText(" – " + distStr); + String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing); + distanceToCenterTv.setText(" – " + distStr + " • " + azimuthStr); } }); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 8a7db92abd..a77b5db097 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -201,12 +201,14 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode()); if (measureDistanceToCenterListener != null) { float distance = 0; + float bearing = 0; if (editingCtx.getPointsCount() > 0) { WptPt lastPoint = editingCtx.getPoints().get(editingCtx.getPointsCount() - 1); LatLon centerLatLon = tb.getCenterLatLon(); distance = (float) MapUtils.getDistance(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude()); + bearing = MapUtils.getBearingToPoint(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude()); } - measureDistanceToCenterListener.onMeasure(distance); + measureDistanceToCenterListener.onMeasure(distance, bearing); } } @@ -423,6 +425,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL } interface OnMeasureDistanceToCenter { - void onMeasure(float distance); + void onMeasure(float distance, float bearing); } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java index 372a945822..e983006cf3 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java @@ -13,6 +13,9 @@ import android.widget.ImageView; import android.widget.TextView; import net.osmand.GPXUtilities.WptPt; +import net.osmand.Location; +import net.osmand.PlatformUtil; +import net.osmand.data.LatLon; import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; @@ -22,15 +25,19 @@ import net.osmand.util.MapUtils; import java.util.Collections; import java.util.List; +import org.apache.commons.logging.Log; public class MeasurementToolAdapter extends RecyclerView.Adapter implements MeasurementToolItemTouchHelperCallback.ItemTouchHelperAdapter { + private static final Log LOG = PlatformUtil.getLog(MeasurementToolAdapter.class); + private final MapActivity mapActivity; private final List points; private MeasurementAdapterListener listener; private boolean nightMode; private final ActionType actionType; + private final static String BULLET = " • "; public MeasurementToolAdapter(MapActivity mapActivity, List points, ActionType actionType) { this.mapActivity = mapActivity; @@ -88,15 +95,27 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter