From 2b5142da063b9fc428b3ddfd17320fb381d17341 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 16 Feb 2017 19:34:02 +0300 Subject: [PATCH] Fix chart while navigating using gpx --- .../ShowRouteInfoDialogFragment.java | 51 +++++++++---------- .../plus/routing/RouteCalculationResult.java | 26 ++++------ 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index 1338dbab0e..e97dd6164c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -28,7 +28,6 @@ import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.utils.Utils; import net.osmand.Location; -import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GPXUtilities; 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.RoutingHelper; import net.osmand.plus.views.TurnPathHelper; -import net.osmand.router.RouteSegmentResult; import net.osmand.util.Algorithms; import java.io.File; @@ -178,35 +176,34 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { private void makeGpx() { double lastHeight = HEIGHT_UNDEFINED; gpx = new GPXFile(); - List route = helper.getRoute().getLeftRoute(); - if (route != null) { + List locations = helper.getRoute().getRouteLocations(); + if (locations != null) { Track track = new Track(); - for (RouteSegmentResult res : route) { - TrkSegment seg = new TrkSegment(); - float[] vls = res.getObject().calculateHeightArray(); - if (!hasHeights && vls != null && vls.length > 0) { - hasHeights = true; - } - int inc = res.getStartPointIndex() < res.getEndPointIndex() ? 1 : -1; - int indexnext = res.getStartPointIndex(); - 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; + 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; } - 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); } } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 60868ed80b..202d76b69c 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -196,20 +196,6 @@ public class RouteCalculationResult { } } - public List getLeftRoute() { - int cs = currentRoute > 0 ? currentRoute - 1 : 0; - if(cs >= segments.size()) { - return null; - } - List list = new ArrayList(); - 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 getOriginalRoute() { if (segments.size() == 0) { return null; @@ -248,8 +234,16 @@ public class RouteCalculationResult { break; } if (vls != null && i * 2 + 1 < vls.length) { - n.setAltitude(vls[2 * i + 1]); - lastHeight = vls[2 * i + 1]; + float h = 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) { n.setAltitude(lastHeight); }