Add text on points from chart
This commit is contained in:
parent
a6520c3f3f
commit
77c568b328
2 changed files with 40 additions and 21 deletions
|
@ -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,16 +303,26 @@ public class TrackDetailsMenu {
|
|||
fitTrackOnMap(chart, location, forceFit);
|
||||
|
||||
if (segment != null) {
|
||||
List<WptPt> pointsOnChart = new ArrayList<>();
|
||||
Map<String, WptPt> pointsOfChart = getPointsOfChart(chart);
|
||||
mapActivity.getMapLayers().getGpxLayer().setPointsOfChart(pointsOfChart);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, WptPt> getPointsOfChart(LineChart chart) {
|
||||
Map<String, WptPt> 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) {
|
||||
pointsOnChart.add(pointToAdd);
|
||||
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);
|
||||
}
|
||||
}
|
||||
mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(pointsOnChart);
|
||||
}
|
||||
return pointsOfChart;
|
||||
}
|
||||
|
||||
private void updateView(final View parentView) {
|
||||
|
|
|
@ -71,7 +71,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
private Bitmap selectedPoint;
|
||||
private LatLon selectedPointLatLon;
|
||||
|
||||
private List<WptPt> pointsOnChart;
|
||||
private Map<String, WptPt> 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<String, WptPt> 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<WptPt> pointsOnChart) {
|
||||
this.pointsOnChart = pointsOnChart;
|
||||
public void setPointsOfChart(Map<String, WptPt> pointsOfChart) {
|
||||
this.pointsOfChart = pointsOfChart;
|
||||
}
|
||||
|
||||
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
||||
|
|
Loading…
Reference in a new issue