Fix x-axis points on route/gpx
This commit is contained in:
parent
20fbb15380
commit
42dfd7a937
3 changed files with 69 additions and 36 deletions
|
@ -61,7 +61,7 @@ public class TrackDetailsMenu {
|
||||||
@Nullable
|
@Nullable
|
||||||
private TrackChartPoints trackChartPoints;
|
private TrackChartPoints trackChartPoints;
|
||||||
@Nullable
|
@Nullable
|
||||||
private List<WptPt> xAxisPoints;
|
private List<LatLon> xAxisPoints;
|
||||||
private int topMarginPx;
|
private int topMarginPx;
|
||||||
private boolean visible;
|
private boolean visible;
|
||||||
private boolean hidding;
|
private boolean hidding;
|
||||||
|
@ -236,8 +236,8 @@ public class TrackDetailsMenu {
|
||||||
return segment;
|
return segment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WptPt getPoint(LineChart chart, float pos) {
|
private LatLon getLocationAtPos(LineChart chart, float pos) {
|
||||||
WptPt wpt = null;
|
LatLon latLon = null;
|
||||||
List<ILineDataSet> ds = chart.getLineData().getDataSets();
|
List<ILineDataSet> ds = chart.getLineData().getDataSets();
|
||||||
GpxDisplayItem gpxItem = getGpxItem();
|
GpxDisplayItem gpxItem = getGpxItem();
|
||||||
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
||||||
|
@ -246,31 +246,50 @@ public class TrackDetailsMenu {
|
||||||
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME ||
|
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME ||
|
||||||
gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||||
float time = pos * 1000;
|
float time = pos * 1000;
|
||||||
for (WptPt p : segment.points) {
|
WptPt previousPoint = null;
|
||||||
if (p.time - gpxItem.analysis.startTime >= time) {
|
for (WptPt currentPoint : segment.points) {
|
||||||
wpt = p;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
previousPoint = currentPoint;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
float distance = pos * dataSet.getDivX();
|
float distance = pos * dataSet.getDivX();
|
||||||
double previousSplitDistance = 0;
|
double previousSplitDistance = 0;
|
||||||
|
WptPt previousPoint = null;
|
||||||
for (int i = 0; i < segment.points.size(); i++) {
|
for (int i = 0; i < segment.points.size(); i++) {
|
||||||
WptPt currentPoint = segment.points.get(i);
|
WptPt currentPoint = segment.points.get(i);
|
||||||
if (i != 0) {
|
if (previousPoint != null) {
|
||||||
WptPt previousPoint = segment.points.get(i - 1);
|
|
||||||
if (currentPoint.distance < previousPoint.distance) {
|
if (currentPoint.distance < previousPoint.distance) {
|
||||||
previousSplitDistance += previousPoint.distance;
|
previousSplitDistance += previousPoint.distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (previousSplitDistance + currentPoint.distance >= distance) {
|
double totalDistance = previousSplitDistance + currentPoint.distance;
|
||||||
wpt = currentPoint;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
previousPoint = currentPoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return wpt;
|
return latLon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private QuadRect getRect(LineChart chart, float startPos, float endPos) {
|
private QuadRect getRect(LineChart chart, float startPos, float endPos) {
|
||||||
|
@ -417,9 +436,8 @@ public class TrackDetailsMenu {
|
||||||
} else {
|
} else {
|
||||||
gpxItem.chartHighlightPos = highlights[0].getX();
|
gpxItem.chartHighlightPos = highlights[0].getX();
|
||||||
}
|
}
|
||||||
WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos);
|
location = getLocationAtPos(chart, gpxItem.chartHighlightPos);
|
||||||
if (wpt != null) {
|
if (location != null) {
|
||||||
location = new LatLon(wpt.lat, wpt.lon);
|
|
||||||
trackChartPoints.setHighlightedPoint(location);
|
trackChartPoints.setHighlightedPoint(location);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -434,7 +452,7 @@ public class TrackDetailsMenu {
|
||||||
fitTrackOnMap(chart, location, forceFit);
|
fitTrackOnMap(chart, location, forceFit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<WptPt> getXAxisPoints(LineChart chart) {
|
private List<LatLon> getXAxisPoints(LineChart chart) {
|
||||||
float[] entries = chart.getXAxis().mEntries;
|
float[] entries = chart.getXAxis().mEntries;
|
||||||
float maxXValue = chart.getLineData().getXMax();
|
float maxXValue = chart.getLineData().getXMax();
|
||||||
if (entries.length >= 2) {
|
if (entries.length >= 2) {
|
||||||
|
@ -443,8 +461,8 @@ public class TrackDetailsMenu {
|
||||||
xAxisPoints = new ArrayList<>();
|
xAxisPoints = new ArrayList<>();
|
||||||
float currentPointEntry = interval;
|
float currentPointEntry = interval;
|
||||||
while (currentPointEntry < maxXValue) {
|
while (currentPointEntry < maxXValue) {
|
||||||
WptPt pointToAdd = getPoint(chart, currentPointEntry);
|
LatLon location = getLocationAtPos(chart, currentPointEntry);
|
||||||
xAxisPoints.add(pointToAdd);
|
xAxisPoints.add(location);
|
||||||
currentPointEntry += interval;
|
currentPointEntry += interval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -740,12 +758,12 @@ public class TrackDetailsMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TrackChartPoints {
|
public static class TrackChartPoints {
|
||||||
private List<WptPt> xAxisPoints;
|
private List<LatLon> xAxisPoints;
|
||||||
private LatLon highlightedPoint;
|
private LatLon highlightedPoint;
|
||||||
private int segmentColor;
|
private int segmentColor;
|
||||||
private GPXFile gpx;
|
private GPXFile gpx;
|
||||||
|
|
||||||
public List<WptPt> getXAxisPoints() {
|
public List<LatLon> getXAxisPoints() {
|
||||||
return xAxisPoints;
|
return xAxisPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +779,7 @@ public class TrackDetailsMenu {
|
||||||
return gpx;
|
return gpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setXAxisPoints(List<WptPt> xAxisPoints) {
|
public void setXAxisPoints(List<LatLon> xAxisPoints) {
|
||||||
this.xAxisPoints = xAxisPoints;
|
this.xAxisPoints = xAxisPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package net.osmand.plus.views;
|
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.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
@ -24,16 +21,16 @@ import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Pair;
|
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.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.data.QuadTree;
|
import net.osmand.data.QuadTree;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
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;
|
||||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
||||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||||
|
@ -60,6 +57,9 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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,
|
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
|
||||||
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<WptPt> {
|
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<WptPt> {
|
||||||
|
|
||||||
|
@ -449,10 +449,14 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
||||||
paintGridCircle.setAlpha(255);
|
paintGridCircle.setAlpha(255);
|
||||||
QuadRect latLonBounds = tileBox.getLatLonBounds();
|
QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||||
float r = 3 * tileBox.getDensity();
|
float r = 3 * tileBox.getDensity();
|
||||||
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
|
List<LatLon> xAxisPoints = trackChartPoints.getXAxisPoints();
|
||||||
if (xAxisPoints != null) {
|
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++) {
|
for (int i = 0; i < xAxisPoints.size(); i++) {
|
||||||
WptPt axisPoint = xAxisPoints.get(i);
|
LatLon axisPoint = xAxisPoints.get(i);
|
||||||
if (axisPoint != null) {
|
if (axisPoint != null) {
|
||||||
if (axisPoint.getLatitude() >= latLonBounds.bottom
|
if (axisPoint.getLatitude() >= latLonBounds.bottom
|
||||||
&& axisPoint.getLatitude() <= latLonBounds.top
|
&& axisPoint.getLatitude() <= latLonBounds.top
|
||||||
|
@ -460,8 +464,12 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
||||||
&& axisPoint.getLongitude() <= latLonBounds.right) {
|
&& axisPoint.getLongitude() <= latLonBounds.right) {
|
||||||
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
||||||
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
||||||
canvas.drawCircle(x, y, r + 2 * (float) Math.ceil(tileBox.getDensity()), paintGridOuterCircle);
|
QuadRect pointRect = new QuadRect(x - outerRadius, y - outerRadius, x + outerRadius, y + outerRadius);
|
||||||
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
|
if (prevPointRect == null || !QuadRect.intersects(prevPointRect, pointRect)) {
|
||||||
|
canvas.drawCircle(x, y, outerRadius, paintGridOuterCircle);
|
||||||
|
canvas.drawCircle(x, y, innerRadius, paintGridCircle);
|
||||||
|
prevPointRect = pointRect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
|
@ -225,18 +224,26 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
||||||
|
|
||||||
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
|
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
|
||||||
QuadRect latLonBounds = tileBox.getLatLonBounds();
|
QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||||
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
|
List<LatLon> xAxisPoints = trackChartPoints.getXAxisPoints();
|
||||||
float r = 3 * tileBox.getDensity();
|
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++) {
|
for (int i = 0; i < xAxisPoints.size(); i++) {
|
||||||
WptPt axisPoint = xAxisPoints.get(i);
|
LatLon axisPoint = xAxisPoints.get(i);
|
||||||
if (axisPoint.getLatitude() >= latLonBounds.bottom
|
if (axisPoint.getLatitude() >= latLonBounds.bottom
|
||||||
&& axisPoint.getLatitude() <= latLonBounds.top
|
&& axisPoint.getLatitude() <= latLonBounds.top
|
||||||
&& axisPoint.getLongitude() >= latLonBounds.left
|
&& axisPoint.getLongitude() >= latLonBounds.left
|
||||||
&& axisPoint.getLongitude() <= latLonBounds.right) {
|
&& axisPoint.getLongitude() <= latLonBounds.right) {
|
||||||
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
||||||
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
|
||||||
canvas.drawCircle(x, y, r + 2 * (float) Math.ceil(tileBox.getDensity()), paintGridOuterCircle);
|
QuadRect pointRect = new QuadRect(x - outerRadius, y - outerRadius, x + outerRadius, y + outerRadius);
|
||||||
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
|
if (prevPointRect == null || !QuadRect.intersects(prevPointRect, pointRect)) {
|
||||||
|
canvas.drawCircle(x, y, outerRadius, paintGridOuterCircle);
|
||||||
|
canvas.drawCircle(x, y, innerRadius, paintGridCircle);
|
||||||
|
prevPointRect = pointRect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue