Show azimuth from last point in measurement tool and in points list
This commit is contained in:
parent
0c8ce1270a
commit
d7948a7316
5 changed files with 64 additions and 7 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MeasurementToolAdapter.MeasureToolItemVH>
|
||||
implements MeasurementToolItemTouchHelperCallback.ItemTouchHelperAdapter {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(MeasurementToolAdapter.class);
|
||||
|
||||
private final MapActivity mapActivity;
|
||||
private final List<WptPt> points;
|
||||
private MeasurementAdapterListener listener;
|
||||
private boolean nightMode;
|
||||
private final ActionType actionType;
|
||||
private final static String BULLET = " • ";
|
||||
|
||||
public MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points, ActionType actionType) {
|
||||
this.mapActivity = mapActivity;
|
||||
|
@ -88,15 +95,27 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
|||
if (!TextUtils.isEmpty(pointDesc)) {
|
||||
holder.descr.setText(pointDesc);
|
||||
} else {
|
||||
String azimuth = "";
|
||||
String text = "";
|
||||
if (pos < 1) {
|
||||
holder.descr.setText(mapActivity.getString(R.string.shared_string_control_start));
|
||||
text = mapActivity.getString(R.string.shared_string_control_start);
|
||||
Location l1 = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
||||
if (mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null) {
|
||||
azimuth = OsmAndFormatter.getFormattedAzimuth(MapUtils.getBearingToPoint(l1, points.get(0).lat, points.get(0).lon));
|
||||
text = text + BULLET + azimuth;
|
||||
}
|
||||
holder.descr.setText(text);
|
||||
} else {
|
||||
float dist = 0;
|
||||
for (int i = 1; i <= pos; i++) {
|
||||
dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon,
|
||||
points.get(i).lat, points.get(i).lon);
|
||||
azimuth = OsmAndFormatter.getFormattedAzimuth(MapUtils.getBearingToPoint(
|
||||
points.get(i-1).lat, points.get(i-1).lon,
|
||||
points.get(i).lat, points.get(i).lon));
|
||||
text = OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()) + BULLET + azimuth;
|
||||
}
|
||||
holder.descr.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
||||
holder.descr.setText(text);
|
||||
}
|
||||
}
|
||||
if (actionType == ActionType.EDIT_SEGMENT) {
|
||||
|
|
Loading…
Reference in a new issue