Add route points to track

This commit is contained in:
PavelRatushny 2017-08-17 15:54:34 +03:00
parent bc3683923a
commit 7f03ce321b
2 changed files with 36 additions and 16 deletions

View file

@ -935,6 +935,19 @@ public class GPXUtilities {
return false; return false;
} }
public void addRoutePoints(List<WptPt> points) {
if (routes.size() == 0) {
Route route = new Route();
routes.add(route);
}
Route lastRoute = routes.get(routes.size() - 1);
lastRoute.points.addAll(points);
modifiedTime = System.currentTimeMillis();
}
public void replaceRoutePoints(List<WptPt> points) { public void replaceRoutePoints(List<WptPt> points) {
routes.clear(); routes.clear();
routes.add(new Route()); routes.add(new Route());

View file

@ -533,7 +533,7 @@ public class MeasurementToolFragment extends Fragment {
public void addToTheTrackOnClick() { public void addToTheTrackOnClick() {
if (mapActivity != null && measurementLayer != null) { if (mapActivity != null && measurementLayer != null) {
if (measurementLayer.getPointsCount() > 0) { if (measurementLayer.getPointsCount() > 0) {
// showAddSegmentDialog(mapActivity); showAddSegmentDialog(mapActivity);
} else { } else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
} }
@ -789,6 +789,9 @@ public class MeasurementToolFragment extends Fragment {
GPXFile gpxFile; GPXFile gpxFile;
if (result != null && result.length > 0) { if (result != null && result.length > 0) {
gpxFile = result[0]; gpxFile = result[0];
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
boolean showOnMap = selectedGpxFile != null;
saveExistingGpx(gpxFile, showOnMap, null, false);
} }
return true; return true;
} }
@ -1059,7 +1062,7 @@ public class MeasurementToolFragment extends Fragment {
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path); SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
boolean showOnMap = selectedGpxFile != null; boolean showOnMap = selectedGpxFile != null;
LineType lineType = newGpxLine.getLineType(); LineType lineType = newGpxLine.getLineType();
saveExistingGpx(gpx, showOnMap, lineType); saveExistingGpx(gpx, showOnMap, lineType, true);
} }
private void saveAsGpx(final SaveType saveType) { private void saveAsGpx(final SaveType saveType) {
@ -1135,8 +1138,8 @@ public class MeasurementToolFragment extends Fragment {
saveGpx(dir, fileName, checked, null, false, null, saveType); saveGpx(dir, fileName, checked, null, false, null, saveType);
} }
private void saveExistingGpx(GPXFile gpx, boolean showOnMap, LineType lineType) { private void saveExistingGpx(GPXFile gpx, boolean showOnMap, LineType lineType, boolean openTrackActivity) {
saveGpx(null, null, showOnMap, gpx, true, lineType, null); saveGpx(null, null, showOnMap, gpx, openTrackActivity, lineType, null);
} }
private void saveGpx(final File dir, private void saveGpx(final File dir,
@ -1195,6 +1198,7 @@ public class MeasurementToolFragment extends Fragment {
toSave = new File(gpx.path); toSave = new File(gpx.path);
if (measurementLayer != null) { if (measurementLayer != null) {
List<WptPt> points = measurementLayer.getMeasurementPoints(); List<WptPt> points = measurementLayer.getMeasurementPoints();
if (lineType != null) {
switch (lineType) { switch (lineType) {
case ADD_SEGMENT: case ADD_SEGMENT:
gpx.addTrkSegment(points); gpx.addTrkSegment(points);
@ -1208,6 +1212,9 @@ public class MeasurementToolFragment extends Fragment {
gpx.replaceSegment(newGpxLine.getTrkSegment(), segment); gpx.replaceSegment(newGpxLine.getTrkSegment(), segment);
break; break;
} }
} else {
gpx.addRoutePoints(points);
}
} }
if (activity != null) { if (activity != null) {
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication()); String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());