Merge pull request #9500 from osmandapp/fix_9464

Fix_9464
This commit is contained in:
vshcherb 2020-07-21 16:54:36 +02:00 committed by GitHub
commit ab993c88de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 29 deletions

View file

@ -153,11 +153,9 @@ public class SelectedGpxMenuBuilder extends MenuBuilder {
OsmAndFormatter.getFormattedSpeed((float) selectedPoint.speed, app), 0, null,
false, null, false, 0, false, false, false, null, false);
}
if (selectedGpxPoint.getPointLocation().hasBearing()) {
buildRow(view, getThemedIcon(R.drawable.ic_action_relative_bearing), null, app.getString(R.string.shared_string_bearing),
OsmAndFormatter.getFormattedAzimuth(selectedGpxPoint.getPointLocation().getBearing(), app), 0, null,
false, null, false, 0, false, false, false, null, false);
}
buildRow(view, getThemedIcon(R.drawable.ic_action_relative_bearing), null, app.getString(R.string.shared_string_bearing),
OsmAndFormatter.getFormattedAzimuth(selectedGpxPoint.getBearing(), app), 0, null,
false, null, false, 0, false, false, false, null, false);
}
private void buildCategoryView(View view, String name) {

View file

@ -10,7 +10,6 @@ import androidx.annotation.NonNull;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.data.PointDescription;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
@ -196,12 +195,12 @@ public class SelectedGpxMenuController extends MenuController {
private final WptPt selectedPoint;
private final SelectedGpxFile selectedGpxFile;
private final Location pointLocation;
private final float bearing;
public SelectedGpxPoint(SelectedGpxFile selectedGpxFile, WptPt selectedPoint, Location pointLocation) {
public SelectedGpxPoint(SelectedGpxFile selectedGpxFile, WptPt selectedPoint, float bearing) {
this.selectedPoint = selectedPoint;
this.selectedGpxFile = selectedGpxFile;
this.pointLocation = pointLocation;
this.bearing = bearing;
}
public WptPt getSelectedPoint() {
@ -212,8 +211,8 @@ public class SelectedGpxMenuController extends MenuController {
return selectedGpxFile;
}
public Location getPointLocation() {
return pointLocation;
public float getBearing() {
return bearing;
}
}
}

View file

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
@ -142,10 +143,10 @@ public class TrackDetailsMenu {
int mx = (int) tb.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
int my = (int) tb.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
int r = (int) (MAX_DISTANCE_LOCATION_PROJECTION * tb.getPixDensity());
WptPt point = GPXLayer.findPointNearSegment(tb, segment.points, r, mx, my);
if (point != null) {
int index = segment.points.indexOf(point);
gpxItem.locationOnMap = GPXLayer.createProjectionPoint(segment.points.get(index - 1), point, tb.getLatLonFromPixel(mx, my));
Pair<WptPt, WptPt> points = GPXLayer.findPointsNearSegment(tb, segment.points, r, mx, my);
if (points != null) {
LatLon latLon = tb.getLatLonFromPixel(mx, my);
gpxItem.locationOnMap = GPXLayer.createProjectionPoint(points.first, points.second, latLon);
float pos = (float) (gpxItem.locationOnMap.distance / ((OrderedLineDataSet) ds.get(0)).getDivX());
float nextVisibleX = chart.getLowestVisibleX() + (pos - gpxItem.chartHighlightPos);
gpxItem.chartHighlightPos = pos;

View file

@ -48,10 +48,10 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.track.SaveGpxAsyncTask;
import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.track.SaveGpxAsyncTask;
import net.osmand.plus.track.TrackDrawInfo;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.ContextMenuLayer.IMoveObjectProvider;
@ -816,11 +816,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
for (TrkSegment segment : segments) {
QuadRect trackBounds = GPXUtilities.calculateBounds(segment.points);
if (QuadRect.trivialOverlap(tb.getLatLonBounds(), trackBounds)) {
WptPt nextPoint = findPointNearSegment(tb, segment.points, r, mx, my);
if (nextPoint != null) {
int index = segment.points.indexOf(nextPoint);
WptPt prevPoint = segment.points.get(index - 1);
SelectedGpxPoint selectedGpxPoint = createSelectedGpxPoint(selectedGpxFile, prevPoint, nextPoint, tb.getLatLonFromPixel(mx, my));
Pair<WptPt, WptPt> points = findPointsNearSegment(tb, segment.points, r, mx, my);
if (points != null) {
LatLon latLon = tb.getLatLonFromPixel(mx, my);
SelectedGpxPoint selectedGpxPoint = createSelectedGpxPoint(selectedGpxFile, points.first, points.second, latLon);
res.add(selectedGpxPoint);
break;
}
@ -829,10 +828,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
}
public static WptPt findPointNearSegment(RotatedTileBox tb, List<WptPt> points, int r, int mx, int my) {
WptPt firstPoint = points.get(0);
int ppx = (int) tb.getPixXFromLatLon(firstPoint.lat, firstPoint.lon);
int ppy = (int) tb.getPixYFromLatLon(firstPoint.lat, firstPoint.lon);
public static Pair<WptPt, WptPt> findPointsNearSegment(RotatedTileBox tb, List<WptPt> points, int r, int mx, int my) {
WptPt prevPoint = points.get(0);
int ppx = (int) tb.getPixXFromLatLon(prevPoint.lat, prevPoint.lon);
int ppy = (int) tb.getPixYFromLatLon(prevPoint.lat, prevPoint.lon);
int pcross = placeInBbox(ppx, ppy, mx, my, r, r);
for (int i = 1; i < points.size(); i++) {
@ -841,7 +840,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
int py = (int) tb.getPixYFromLatLon(point.lat, point.lon);
int cross = placeInBbox(px, py, mx, my, r, r);
if (cross == 0) {
return point;
return new Pair<>(prevPoint, point);
}
if ((pcross & cross) == 0) {
int mpx = px;
@ -852,7 +851,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
int mpynew = mpy / 2 + ppy / 2;
int mcrossnew = placeInBbox(mpxnew, mpynew, mx, my, r, r);
if (mcrossnew == 0) {
return point;
return new Pair<>(prevPoint, point);
}
if ((mcrossnew & mcross) != 0) {
mpx = mpxnew;
@ -871,6 +870,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
pcross = cross;
ppx = px;
ppy = py;
prevPoint = point;
}
return null;
}
@ -886,9 +886,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
nextPointLocation.setLatitude(nextPoint.lat);
nextPointLocation.setLongitude(nextPoint.lon);
prevPointLocation.setBearing(prevPointLocation.bearingTo(nextPointLocation));
float bearing = prevPointLocation.bearingTo(nextPointLocation);
return new SelectedGpxPoint(selectedGpxFile, projectionPoint, prevPointLocation);
return new SelectedGpxPoint(selectedGpxFile, projectionPoint, bearing);
}
public static WptPt createProjectionPoint(WptPt prevPoint, WptPt nextPoint, LatLon latLon) {