use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class TrackDetailsMenu method getPoint.
private WptPt getPoint(LineChart chart, float pos) {
WptPt wpt = null;
List<ILineDataSet> ds = chart.getLineData().getDataSets();
if (ds != null && ds.size() > 0) {
TrkSegment segment = getTrackSegment(chart);
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
float time = pos * 1000;
for (WptPt p : segment.points) {
if (p.time - gpxItem.analysis.startTime >= time) {
wpt = p;
break;
}
}
} else {
float distance = pos * dataSet.getDivX();
double previousSplitDistance = 0;
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 (currentPoint.distance < previousPoint.distance) {
previousSplitDistance += previousPoint.distance;
}
}
if (previousSplitDistance + currentPoint.distance >= distance) {
wpt = currentPoint;
break;
}
}
}
}
return wpt;
}
use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class TrackDetailsMenu method refreshChart.
private void refreshChart(LineChart chart, boolean forceFit) {
Highlight[] highlights = chart.getHighlighted();
LatLon location = null;
if (trackChartPoints == null) {
trackChartPoints = new TrackChartPoints();
TrkSegment segment = getTrackSegment(chart);
int segmentColor = segment != null ? segment.getColor(0) : 0;
trackChartPoints.setSegmentColor(segmentColor);
trackChartPoints.setGpx(getGpxItem().group.getGpx());
}
float minimumVisibleXValue = chart.getLowestVisibleX();
float maximumVisibleXValue = chart.getHighestVisibleX();
if (highlights != null && highlights.length > 0) {
if (minimumVisibleXValue != 0 && maximumVisibleXValue != 0) {
if (highlights[0].getX() < minimumVisibleXValue) {
float difference = (maximumVisibleXValue - minimumVisibleXValue) * 0.1f;
gpxItem.chartHighlightPos = minimumVisibleXValue + difference;
chart.highlightValue(minimumVisibleXValue + difference, 0);
} else if (highlights[0].getX() > maximumVisibleXValue) {
float difference = (maximumVisibleXValue - minimumVisibleXValue) * 0.1f;
gpxItem.chartHighlightPos = maximumVisibleXValue - difference;
chart.highlightValue(maximumVisibleXValue - difference, 0);
} else {
gpxItem.chartHighlightPos = highlights[0].getX();
}
} else {
gpxItem.chartHighlightPos = highlights[0].getX();
}
WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos);
if (wpt != null) {
location = new LatLon(wpt.lat, wpt.lon);
trackChartPoints.setHighlightedPoint(location);
}
} else {
gpxItem.chartHighlightPos = -1;
}
trackChartPoints.setXAxisPoints(getXAxisPoints(chart));
if (gpxItem.route) {
mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(trackChartPoints);
} else {
mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints);
}
fitTrackOnMap(chart, location, forceFit);
}
use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class SavingTrackHelper method addTrackPoint.
private void addTrackPoint(WptPt pt, boolean newSegment, long time) {
List<TrkSegment> points = currentTrack.getModifiablePointsToDisplay();
Track track = currentTrack.getModifiableGpxFile().tracks.get(0);
assert track.segments.size() == points.size();
if (points.size() == 0 || newSegment) {
points.add(new TrkSegment());
}
boolean segmentAdded = false;
if (track.segments.size() == 0 || newSegment) {
track.segments.add(new TrkSegment());
segmentAdded = true;
}
if (pt != null) {
int ind = points.size() - 1;
TrkSegment last = points.get(ind);
last.points.add(pt);
TrkSegment lt = track.segments.get(track.segments.size() - 1);
lt.points.add(pt);
}
if (segmentAdded) {
currentTrack.processPoints();
}
currentTrack.getModifiableGpxFile().modifiedTime = time;
}
use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class SavingTrackHelper method prepareCurrentTrackForRecording.
private void prepareCurrentTrackForRecording() {
if (currentTrack.getModifiableGpxFile().tracks.size() == 0) {
currentTrack.getModifiableGpxFile().tracks.add(new Track());
}
while (currentTrack.getPointsToDisplay().size() < currentTrack.getModifiableGpxFile().tracks.size()) {
TrkSegment trkSegment = new TrkSegment();
currentTrack.getModifiablePointsToDisplay().add(trkSegment);
}
}
use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class ShowRouteInfoDialogFragment method makeGpx.
private void makeGpx() {
double lastHeight = HEIGHT_UNDEFINED;
gpx = new GPXFile();
List<Location> locations = helper.getRoute().getRouteLocations();
if (locations != null) {
Track track = new Track();
TrkSegment seg = new TrkSegment();
for (Location l : locations) {
WptPt point = new WptPt();
point.lat = l.getLatitude();
point.lon = l.getLongitude();
if (l.hasAltitude()) {
if (!hasHeights) {
hasHeights = true;
}
float h = (float) l.getAltitude();
point.ele = h;
if (lastHeight == HEIGHT_UNDEFINED && seg.points.size() > 0) {
for (WptPt pt : seg.points) {
if (Double.isNaN(pt.ele)) {
pt.ele = h;
}
}
}
lastHeight = h;
}
seg.points.add(point);
}
track.segments.add(seg);
gpx.tracks.add(track);
String groupName = getMyApplication().getString(R.string.current_route);
GpxDisplayGroup group = getMyApplication().getSelectedGpxHelper().buildGpxDisplayGroup(gpx, 0, groupName);
if (group != null && group.getModifiableList().size() > 0) {
gpxItem = group.getModifiableList().get(0);
if (gpxItem != null) {
gpxItem.route = true;
}
}
}
}
Aggregations