Save points as route points for distance measurement (if there is only 1 path)
This commit is contained in:
parent
654bf79dbe
commit
a233194807
2 changed files with 24 additions and 12 deletions
|
@ -782,7 +782,6 @@
|
|||
<string name="distance_measurement_finish_editing">Finish editing</string>
|
||||
<string name="distance_measurement_finish_subtrack">Begin a new subtrack</string>
|
||||
<string name="distance_measurement_clear_route">Clear all points</string>
|
||||
<string name="distance_measurement_save_gpx">Save as GPX</string>
|
||||
<string name="distance_measurement_load_gpx">Open existing GPX</string>
|
||||
<string name="wait_current_task_finished">Please wait until current task is finished</string>
|
||||
<string name="use_kalman_filter_compass_descr">Reduces noise in compass readings but adds inertia</string>
|
||||
|
|
|
@ -154,7 +154,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
if(measurementPoints.size() > 0) {
|
||||
list.add(R.string.distance_measurement_finish_subtrack);
|
||||
list.add(R.string.distance_measurement_clear_route);
|
||||
list.add(R.string.distance_measurement_save_gpx);
|
||||
list.add(R.string.shared_string_save_as_gpx);
|
||||
}
|
||||
list.add(R.string.distance_measurement_load_gpx);
|
||||
String[] items = new String[list.size()];
|
||||
|
@ -177,7 +177,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
distanceMeasurementMode = 0;
|
||||
measurementPoints.clear();
|
||||
calculateDistance();
|
||||
} else if (id == R.string.distance_measurement_save_gpx) {
|
||||
} else if (id == R.string.shared_string_save_as_gpx) {
|
||||
saveGpx(activity);
|
||||
} else if (id == R.string.distance_measurement_load_gpx) {
|
||||
loadGpx(activity);
|
||||
|
@ -234,13 +234,26 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||
LinearLayout ll = new LinearLayout(activity);
|
||||
ll.setOrientation(LinearLayout.VERTICAL);
|
||||
ll.setPadding(5, 5, 5, 5);
|
||||
ll.setPadding(7, 7, 7, 7);
|
||||
final TextView tv = new TextView(activity);
|
||||
tv.setText("");
|
||||
|
||||
tv.setTextColor(Color.RED);
|
||||
ll.addView(tv);
|
||||
final EditText editText = new EditText(activity);
|
||||
editText.setHint(R.string.gpx_file_name);
|
||||
if(originalGPX != null && originalGPX.path != null){
|
||||
String p = originalGPX.path;
|
||||
int li = p.lastIndexOf('/');
|
||||
if(li >= 0) {
|
||||
p = p.substring(li + 1);
|
||||
}
|
||||
int pi = p.lastIndexOf('.');
|
||||
if(pi >= 0) {
|
||||
p = p.substring(0, pi);
|
||||
}
|
||||
editText.setText(p);
|
||||
}
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
@Override
|
||||
|
@ -291,8 +304,8 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
protected String doInBackground(Void... params) {
|
||||
toSave = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), fileNameSave);
|
||||
GPXFile gpx;
|
||||
boolean saveTrackToRte = false;
|
||||
if(originalGPX != null) {
|
||||
boolean saveTrackToRte = measurementPoints.size() <= 1;
|
||||
if (originalGPX != null) {
|
||||
gpx = originalGPX;
|
||||
saveTrackToRte = originalGPX.routes.size() > 0 && originalGPX.tracks.size() == 0;
|
||||
gpx.tracks.clear();
|
||||
|
@ -301,17 +314,17 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
} else {
|
||||
gpx = new GPXFile();
|
||||
}
|
||||
for(int i = 0; i<measurementPoints.size(); i++) {
|
||||
for (int i = 0; i < measurementPoints.size(); i++) {
|
||||
LinkedList<WptPt> lt = measurementPoints.get(i);
|
||||
if(lt.size() == 1) {
|
||||
if (lt.size() == 1) {
|
||||
gpx.points.add(lt.getFirst());
|
||||
} else if(lt.size() > 1) {
|
||||
if(saveTrackToRte) {
|
||||
} else if (lt.size() > 1) {
|
||||
if (saveTrackToRte) {
|
||||
Route rt = new Route();
|
||||
gpx.routes.add(rt);
|
||||
rt.points.addAll(lt);
|
||||
} else {
|
||||
if(gpx.tracks.size() == 0) {
|
||||
if (gpx.tracks.size() == 0) {
|
||||
gpx.tracks.add(new Track());
|
||||
}
|
||||
Track ts = gpx.tracks.get(gpx.tracks.size() - 1);
|
||||
|
|
Loading…
Reference in a new issue