From 9768ff83f67988b322be62f62622a26eac4c5b56 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 23 Oct 2017 14:11:46 +0300 Subject: [PATCH] Fix saving in measurement distance (cherry picked from commit 7181346) --- .../MeasurementToolFragment.java | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index b65a26e9af..a87ab95735 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -68,6 +68,7 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll import java.io.File; import java.text.MessageFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; @@ -112,8 +113,7 @@ public class MeasurementToolFragment extends Fragment { private enum SaveType { ROUTE_POINT, - LINE, - SNAP_TO_ROAD + LINE } private void setEditingCtx(MeasurementEditingContext editingCtx) { @@ -671,7 +671,7 @@ public class MeasurementToolFragment extends Fragment { return new SaveAsNewTrackFragmentListener() { @Override public void saveAsRoutePointOnClick() { - saveAsGpx(editingCtx.isInSnapToRoadMode() ? SaveType.SNAP_TO_ROAD : SaveType.ROUTE_POINT); + saveAsGpx(SaveType.ROUTE_POINT); } @Override @@ -1182,34 +1182,36 @@ public class MeasurementToolFragment extends Fragment { protected String doInBackground(Void... voids) { MeasurementToolLayer measurementLayer = getMeasurementLayer(); MapActivity activity = getMapActivity(); + List points = editingCtx.getPoints(); + TrkSegment before = editingCtx.getBeforeTrkSegmentLine(); + TrkSegment after = editingCtx.getAfterTrkSegmentLine(); if (gpx == null) { toSave = new File(dir, fileName); GPXFile gpx = new GPXFile(); if (measurementLayer != null) { - List points = editingCtx.getPoints(); if (saveType == SaveType.LINE) { TrkSegment segment = new TrkSegment(); - segment.points.addAll(points); + if (editingCtx.isInSnapToRoadMode()) { + segment.points.addAll(before.points); + segment.points.addAll(after.points); + } else { + segment.points.addAll(points); + } Track track = new Track(); track.segments.add(segment); gpx.tracks.add(track); } else if (saveType == SaveType.ROUTE_POINT) { + if (editingCtx.isInSnapToRoadMode()) { + TrkSegment segment = new TrkSegment(); + segment.points.addAll(before.points); + segment.points.addAll(after.points); + Track track = new Track(); + track.segments.add(segment); + gpx.tracks.add(track); + } Route rt = new Route(); gpx.routes.add(rt); rt.points.addAll(points); - } else if (saveType == SaveType.SNAP_TO_ROAD) { - TrkSegment segmentToSave = new TrkSegment(); - TrkSegment before = editingCtx.getBeforeTrkSegmentLine(); - TrkSegment after = editingCtx.getAfterTrkSegmentLine(); - segmentToSave.points.addAll(before.points); - segmentToSave.points.addAll(after.points); - Track track = new Track(); - track.segments.add(segmentToSave); - gpx.tracks.add(track); - - Route rt = new Route(); - rt.points.addAll(points); - gpx.routes.add(rt); } } if (activity != null) { @@ -1223,11 +1225,17 @@ public class MeasurementToolFragment extends Fragment { } else { toSave = new File(gpx.path); if (measurementLayer != null) { - List points = editingCtx.getPoints(); if (actionType != null) { switch (actionType) { case ADD_SEGMENT: - gpx.addTrkSegment(points); + if (editingCtx.isInSnapToRoadMode()) { + List snappedPoints = new ArrayList<>(); + snappedPoints.addAll(before.points); + snappedPoints.addAll(after.points); + gpx.addTrkSegment(snappedPoints); + } else { + gpx.addTrkSegment(points); + } break; case ADD_ROUTE_POINTS: gpx.replaceRoutePoints(points); @@ -1425,13 +1433,7 @@ public class MeasurementToolFragment extends Fragment { fileName = name + "_" + (++ind) + GPX_SUFFIX; fout = new File(dir, fileName); } - SaveType saveType; - if (editingCtx.isInSnapToRoadMode()) { - saveType = SaveType.SNAP_TO_ROAD; - } else { - saveType = SaveType.LINE; - } - saveNewGpx(dir, fileName, true, saveType, true); + saveNewGpx(dir, fileName, true, SaveType.LINE, true); } else { dismiss(mapActivity); }