diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 01f654f0e7..37b2684f90 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -12,6 +12,7 @@ import android.widget.TextView; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; +import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; @@ -43,7 +44,9 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class TrackDetailsMenu { @@ -141,7 +144,7 @@ public class TrackDetailsMenu { } mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode(); mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(null); - mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(null); + mapActivity.getMapLayers().getGpxLayer().setPointsOfChart(null); mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(null); mapActivity.getMapView().setMapPositionX(0); mapActivity.getMapView().refreshMap(); @@ -300,18 +303,28 @@ public class TrackDetailsMenu { fitTrackOnMap(chart, location, forceFit); if (segment != null) { - List pointsOnChart = new ArrayList<>(); - float[] entries = chart.getXAxis().mEntries; - for (int i = 0; i < entries.length; i++) { - WptPt pointToAdd = getPoint(chart, entries[i]); - if (pointToAdd != null) { - pointsOnChart.add(pointToAdd); - } - } - mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(pointsOnChart); + Map pointsOfChart = getPointsOfChart(chart); + mapActivity.getMapLayers().getGpxLayer().setPointsOfChart(pointsOfChart); } } + private Map getPointsOfChart(LineChart chart) { + Map pointsOfChart = new HashMap<>(); + float[] entries = chart.getXAxis().mEntries; + for (int i = 0; i < entries.length; i++) { + WptPt pointToAdd = getPoint(chart, entries[i]); + if (pointToAdd != null) { + if (gpxItem.chartAxisType == GPXDataSetAxisType.DISTANCE) { + pointsOfChart.put(String.format("%.1f", entries[i]), pointToAdd); + } else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) { + IAxisValueFormatter formatter = chart.getXAxis().getValueFormatter(); + pointsOfChart.put(formatter.getFormattedValue(entries[i], chart.getXAxis()), pointToAdd); + } + } + } + return pointsOfChart; + } + private void updateView(final View parentView) { GPXTrackAnalysis analysis = gpxItem.analysis; if (analysis == null || gpxItem.chartTypes == null) { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 834e7b1b28..89e023b8ff 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -71,7 +71,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private Bitmap selectedPoint; private LatLon selectedPointLatLon; - private List pointsOnChart; + private Map pointsOfChart; private static final int startZoom = 7; @@ -351,14 +351,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex drawBigPoint(canvas, o, fileColor, x, y); } } - if (pointsOnChart != null) { - for (WptPt pointOnChart : pointsOnChart) { - float x = tileBox.getPixXFromLatLon(pointOnChart.getLatitude(), pointOnChart.getLongitude()); - float y = tileBox.getPixYFromLatLon(pointOnChart.getLatitude(), pointOnChart.getLongitude()); - int pointColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_color_point); - paintIcon.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.MULTIPLY)); - canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); - } + if (pointsOfChart != null) { + drawPointsOfChart(canvas, tileBox); } if (selectedPointLatLon != null && selectedPointLatLon.getLatitude() >= latLonBounds.bottom @@ -375,6 +369,18 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } } + private void drawPointsOfChart(Canvas canvas, RotatedTileBox tileBox) { + for (Map.Entry pointOfChart : pointsOfChart.entrySet()) { + float r = 12 * tileBox.getDensity(); + float x = tileBox.getPixXFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); + float y = tileBox.getPixYFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); + canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintOuter); + canvas.drawCircle(x, y, r - (float) Math.ceil(tileBox.getDensity()), paintInnerCircle); + paintTextIcon.setTextSize(r); + canvas.drawText(pointOfChart.getKey(), x, y + r / 2, paintTextIcon); + } + } + private int getFileColor(@NonNull SelectedGpxFile g) { return g.getColor() == 0 ? defPointColor : g.getColor(); } @@ -443,8 +449,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex this.selectedPointLatLon = selectedPointLatLon; } - public void setPointsOnChart(List pointsOnChart) { - this.pointsOnChart = pointsOnChart; + public void setPointsOfChart(Map pointsOfChart) { + this.pointsOfChart = pointsOfChart; } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {