Fix x-axis points on route/gpx

This commit is contained in:
crimean 2019-04-22 12:17:07 +03:00
parent 20fbb15380
commit 42dfd7a937
3 changed files with 69 additions and 36 deletions

View file

@ -61,7 +61,7 @@ public class TrackDetailsMenu {
@Nullable
private TrackChartPoints trackChartPoints;
@Nullable
private List<WptPt> xAxisPoints;
private List<LatLon> xAxisPoints;
private int topMarginPx;
private boolean visible;
private boolean hidding;
@ -236,8 +236,8 @@ public class TrackDetailsMenu {
return segment;
}
private WptPt getPoint(LineChart chart, float pos) {
WptPt wpt = null;
private LatLon getLocationAtPos(LineChart chart, float pos) {
LatLon latLon = null;
List<ILineDataSet> ds = chart.getLineData().getDataSets();
GpxDisplayItem gpxItem = getGpxItem();
if (ds != null && ds.size() > 0 && gpxItem != null) {
@ -246,31 +246,50 @@ public class TrackDetailsMenu {
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME ||
gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
float time = pos * 1000;
for (WptPt p : segment.points) {
if (p.time - gpxItem.analysis.startTime >= time) {
wpt = p;
WptPt previousPoint = null;
for (WptPt currentPoint : segment.points) {
long totalTime = currentPoint.time - gpxItem.analysis.startTime;
if (totalTime >= time) {
if (previousPoint != null) {
double percent = 1 - (totalTime - time) / (currentPoint.time - previousPoint.time);
double dLat = (currentPoint.lat - previousPoint.lat) * percent;
double dLon = (currentPoint.lon - previousPoint.lon) * percent;
latLon = new LatLon(previousPoint.lat + dLat, previousPoint.lon + dLon);
} else {
latLon = new LatLon(currentPoint.lat, currentPoint.lon);
}
break;
}
previousPoint = currentPoint;
}
} else {
float distance = pos * dataSet.getDivX();
double previousSplitDistance = 0;
WptPt previousPoint = null;
for (int i = 0; i < segment.points.size(); i++) {
WptPt currentPoint = segment.points.get(i);
if (i != 0) {
WptPt previousPoint = segment.points.get(i - 1);
if (previousPoint != null) {
if (currentPoint.distance < previousPoint.distance) {
previousSplitDistance += previousPoint.distance;
}
}
if (previousSplitDistance + currentPoint.distance >= distance) {
wpt = currentPoint;
double totalDistance = previousSplitDistance + currentPoint.distance;
if (totalDistance >= distance) {
if (previousPoint != null) {
double percent = 1 - (totalDistance - distance) / (currentPoint.distance - previousPoint.distance);
double dLat = (currentPoint.lat - previousPoint.lat) * percent;
double dLon = (currentPoint.lon - previousPoint.lon) * percent;
latLon = new LatLon(previousPoint.lat + dLat, previousPoint.lon + dLon);
} else {
latLon = new LatLon(currentPoint.lat, currentPoint.lon);
}
break;
}
previousPoint = currentPoint;
}
}
}
return wpt;
return latLon;
}
private QuadRect getRect(LineChart chart, float startPos, float endPos) {
@ -417,9 +436,8 @@ public class TrackDetailsMenu {
} else {
gpxItem.chartHighlightPos = highlights[0].getX();
}
WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos);
if (wpt != null) {
location = new LatLon(wpt.lat, wpt.lon);
location = getLocationAtPos(chart, gpxItem.chartHighlightPos);
if (location != null) {
trackChartPoints.setHighlightedPoint(location);
}
} else {
@ -434,7 +452,7 @@ public class TrackDetailsMenu {
fitTrackOnMap(chart, location, forceFit);
}
private List<WptPt> getXAxisPoints(LineChart chart) {
private List<LatLon> getXAxisPoints(LineChart chart) {
float[] entries = chart.getXAxis().mEntries;
float maxXValue = chart.getLineData().getXMax();
if (entries.length >= 2) {
@ -443,8 +461,8 @@ public class TrackDetailsMenu {
xAxisPoints = new ArrayList<>();
float currentPointEntry = interval;
while (currentPointEntry < maxXValue) {
WptPt pointToAdd = getPoint(chart, currentPointEntry);
xAxisPoints.add(pointToAdd);
LatLon location = getLocationAtPos(chart, currentPointEntry);
xAxisPoints.add(location);
currentPointEntry += interval;
}
}
@ -740,12 +758,12 @@ public class TrackDetailsMenu {
}
public static class TrackChartPoints {
private List<WptPt> xAxisPoints;
private List<LatLon> xAxisPoints;
private LatLon highlightedPoint;
private int segmentColor;
private GPXFile gpx;
public List<WptPt> getXAxisPoints() {
public List<LatLon> getXAxisPoints() {
return xAxisPoints;
}
@ -761,7 +779,7 @@ public class TrackDetailsMenu {
return gpx;
}
public void setXAxisPoints(List<WptPt> xAxisPoints) {
public void setXAxisPoints(List<LatLon> xAxisPoints) {
this.xAxisPoints = xAxisPoints;
}

View file

@ -1,8 +1,5 @@
package net.osmand.plus.views;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@ -24,16 +21,16 @@ import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Pair;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
@ -60,6 +57,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<WptPt> {
@ -449,10 +449,14 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paintGridCircle.setAlpha(255);
QuadRect latLonBounds = tileBox.getLatLonBounds();
float r = 3 * tileBox.getDensity();
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
List<LatLon> xAxisPoints = trackChartPoints.getXAxisPoints();
if (xAxisPoints != null) {
float density = (float) Math.ceil(tileBox.getDensity());
float outerRadius = r + 2 * density;
float innerRadius = r + density;
QuadRect prevPointRect = null;
for (int i = 0; i < xAxisPoints.size(); i++) {
WptPt axisPoint = xAxisPoints.get(i);
LatLon axisPoint = xAxisPoints.get(i);
if (axisPoint != null) {
if (axisPoint.getLatitude() >= latLonBounds.bottom
&& axisPoint.getLatitude() <= latLonBounds.top
@ -460,8 +464,12 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
&& axisPoint.getLongitude() <= latLonBounds.right) {
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
canvas.drawCircle(x, y, r + 2 * (float) Math.ceil(tileBox.getDensity()), paintGridOuterCircle);
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
QuadRect pointRect = new QuadRect(x - outerRadius, y - outerRadius, x + outerRadius, y + outerRadius);
if (prevPointRect == null || !QuadRect.intersects(prevPointRect, pointRect)) {
canvas.drawCircle(x, y, outerRadius, paintGridOuterCircle);
canvas.drawCircle(x, y, innerRadius, paintGridCircle);
prevPointRect = pointRect;
}
}
}
}

View file

@ -16,7 +16,6 @@ import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Pair;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@ -225,18 +224,26 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds();
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
List<LatLon> xAxisPoints = trackChartPoints.getXAxisPoints();
float r = 3 * tileBox.getDensity();
float density = (float) Math.ceil(tileBox.getDensity());
float outerRadius = r + 2 * density;
float innerRadius = r + density;
QuadRect prevPointRect = null;
for (int i = 0; i < xAxisPoints.size(); i++) {
WptPt axisPoint = xAxisPoints.get(i);
LatLon axisPoint = xAxisPoints.get(i);
if (axisPoint.getLatitude() >= latLonBounds.bottom
&& axisPoint.getLatitude() <= latLonBounds.top
&& axisPoint.getLongitude() >= latLonBounds.left
&& axisPoint.getLongitude() <= latLonBounds.right) {
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
canvas.drawCircle(x, y, r + 2 * (float) Math.ceil(tileBox.getDensity()), paintGridOuterCircle);
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
QuadRect pointRect = new QuadRect(x - outerRadius, y - outerRadius, x + outerRadius, y + outerRadius);
if (prevPointRect == null || !QuadRect.intersects(prevPointRect, pointRect)) {
canvas.drawCircle(x, y, outerRadius, paintGridOuterCircle);
canvas.drawCircle(x, y, innerRadius, paintGridCircle);
prevPointRect = pointRect;
}
}
}
}