Fix chart while navigating using gpx
This commit is contained in:
parent
db55b50704
commit
2b5142da06
2 changed files with 34 additions and 43 deletions
|
@ -28,7 +28,6 @@ import com.github.mikephil.charting.charts.LineChart;
|
||||||
import com.github.mikephil.charting.utils.Utils;
|
import com.github.mikephil.charting.utils.Utils;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.data.LatLon;
|
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
|
@ -45,7 +44,6 @@ import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||||
import net.osmand.plus.routing.RouteDirectionInfo;
|
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.views.TurnPathHelper;
|
import net.osmand.plus.views.TurnPathHelper;
|
||||||
import net.osmand.router.RouteSegmentResult;
|
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -178,35 +176,34 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
|
||||||
private void makeGpx() {
|
private void makeGpx() {
|
||||||
double lastHeight = HEIGHT_UNDEFINED;
|
double lastHeight = HEIGHT_UNDEFINED;
|
||||||
gpx = new GPXFile();
|
gpx = new GPXFile();
|
||||||
List<RouteSegmentResult> route = helper.getRoute().getLeftRoute();
|
List<Location> locations = helper.getRoute().getRouteLocations();
|
||||||
if (route != null) {
|
if (locations != null) {
|
||||||
Track track = new Track();
|
Track track = new Track();
|
||||||
for (RouteSegmentResult res : route) {
|
TrkSegment seg = new TrkSegment();
|
||||||
TrkSegment seg = new TrkSegment();
|
for (Location l : locations) {
|
||||||
float[] vls = res.getObject().calculateHeightArray();
|
WptPt point = new WptPt();
|
||||||
if (!hasHeights && vls != null && vls.length > 0) {
|
point.lat = l.getLatitude();
|
||||||
hasHeights = true;
|
point.lon = l.getLongitude();
|
||||||
}
|
if (l.hasAltitude()) {
|
||||||
int inc = res.getStartPointIndex() < res.getEndPointIndex() ? 1 : -1;
|
if (!hasHeights) {
|
||||||
int indexnext = res.getStartPointIndex();
|
hasHeights = true;
|
||||||
for (int index = res.getStartPointIndex(); index != res.getEndPointIndex(); ) {
|
|
||||||
index = indexnext;
|
|
||||||
indexnext += inc;
|
|
||||||
LatLon l = res.getPoint(index);
|
|
||||||
WptPt point = new WptPt();
|
|
||||||
point.lat = l.getLatitude();
|
|
||||||
point.lon = l.getLongitude();
|
|
||||||
if (vls != null && index * 2 + 1 < vls.length) {
|
|
||||||
point.ele = vls[2 * index + 1];
|
|
||||||
//point.desc = (res.getObject().getId() >> (BinaryInspector.SHIFT_ID )) + " " + index;
|
|
||||||
lastHeight = vls[2 * index + 1];
|
|
||||||
} else if (lastHeight != HEIGHT_UNDEFINED) {
|
|
||||||
point.ele = lastHeight;
|
|
||||||
}
|
}
|
||||||
seg.points.add(point);
|
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;
|
||||||
|
} else if (lastHeight != HEIGHT_UNDEFINED) {
|
||||||
|
point.ele = lastHeight;
|
||||||
}
|
}
|
||||||
track.segments.add(seg);
|
seg.points.add(point);
|
||||||
}
|
}
|
||||||
|
track.segments.add(seg);
|
||||||
gpx.tracks.add(track);
|
gpx.tracks.add(track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,20 +196,6 @@ public class RouteCalculationResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RouteSegmentResult> getLeftRoute() {
|
|
||||||
int cs = currentRoute > 0 ? currentRoute - 1 : 0;
|
|
||||||
if(cs >= segments.size()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<RouteSegmentResult> list = new ArrayList<RouteSegmentResult>();
|
|
||||||
for (int i = cs; i < segments.size(); i++) {
|
|
||||||
if (i == cs || segments.get(i - 1) != segments.get(i)) {
|
|
||||||
list.add(segments.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RouteSegmentResult> getOriginalRoute() {
|
public List<RouteSegmentResult> getOriginalRoute() {
|
||||||
if (segments.size() == 0) {
|
if (segments.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -248,8 +234,16 @@ public class RouteCalculationResult {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (vls != null && i * 2 + 1 < vls.length) {
|
if (vls != null && i * 2 + 1 < vls.length) {
|
||||||
n.setAltitude(vls[2 * i + 1]);
|
float h = vls[2 * i + 1];
|
||||||
lastHeight = vls[2 * i + 1];
|
n.setAltitude(h);
|
||||||
|
if (lastHeight == HEIGHT_UNDEFINED && locations.size() > 0) {
|
||||||
|
for (Location l : locations) {
|
||||||
|
if (!l.hasAltitude()) {
|
||||||
|
l.setAltitude(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastHeight = h;
|
||||||
} else if (lastHeight != HEIGHT_UNDEFINED) {
|
} else if (lastHeight != HEIGHT_UNDEFINED) {
|
||||||
n.setAltitude(lastHeight);
|
n.setAltitude(lastHeight);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue