From f479debb79855ec328d0d098ea27c2d2a24dabe2 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 10 Jul 2020 16:56:55 +0300 Subject: [PATCH] Fix #8318 --- .../src/main/java/net/osmand/GPXUtilities.java | 1 - .../mapcontextmenu/other/TrackDetailsMenu.java | 15 ++++++++------- .../plus/myplaces/TrackSegmentFragment.java | 11 +++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 6eb20d0f15..d5e404a76f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -932,7 +932,6 @@ public class GPXUtilities { sp = new SplitSegment(segment, k - 1, cf); currentMetricEnd += metricLimit; - prev = sp.get(0); } total += currentSegment; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index fdc58e7831..586a301d45 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -46,6 +46,7 @@ import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.views.GPXLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; +import net.osmand.util.MapUtils; import java.util.ArrayList; import java.util.Collections; @@ -312,18 +313,15 @@ public class TrackDetailsMenu { } } else { float distance = pos * dataSet.getDivX(); - double previousSplitDistance = 0; + double totalDistance = 0; WptPt previousPoint = null; for (int i = 0; i < segment.points.size(); i++) { WptPt currentPoint = segment.points.get(i); if (previousPoint != null) { - if (currentPoint.distance < previousPoint.distance) { - previousSplitDistance += previousPoint.distance; - } + totalDistance += MapUtils.getDistance(previousPoint.lat, previousPoint.lon, currentPoint.lat, currentPoint.lon); } - double totalDistance = previousSplitDistance + currentPoint.distance; - if (totalDistance >= distance) { - if (previousPoint != null) { + if (currentPoint.distance >= distance || Math.abs(totalDistance - distance) < 0.1) { + if (previousPoint != null && currentPoint.distance >= distance) { double percent = 1 - (totalDistance - distance) / (currentPoint.distance - previousPoint.distance); double dLat = (currentPoint.lat - previousPoint.lat) * percent; double dLon = (currentPoint.lon - previousPoint.lon) * percent; @@ -500,6 +498,9 @@ public class TrackDetailsMenu { } else { mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints); } + if (location != null) { + mapActivity.refreshMap(); + } fitTrackOnMap(chart, location, forceFit); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 8207d401ff..41343f0fa3 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -57,7 +57,6 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -70,12 +69,14 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.controls.PagerSlidingTabStrip; import net.osmand.plus.views.controls.PagerSlidingTabStrip.CustomTabProvider; import net.osmand.plus.views.controls.WrapContentHeightViewPager; import net.osmand.plus.views.controls.WrapContentHeightViewPager.ViewAtPositionInterface; import net.osmand.plus.widgets.IconPopupMenu; import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; import java.io.File; import java.lang.ref.WeakReference; @@ -525,16 +526,14 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit } } else { float distance = pos * dataSet.getDivX(); - double previousSplitDistance = 0; + double totalDistance = 0; for (int i = 0; i < segment.points.size(); i++) { WptPt currentPoint = segment.points.get(i); if (i != 0) { WptPt previousPoint = segment.points.get(i - 1); - if (currentPoint.distance < previousPoint.distance) { - previousSplitDistance += previousPoint.distance; - } + totalDistance += MapUtils.getDistance(previousPoint.lat, previousPoint.lon, currentPoint.lat, currentPoint.lon); } - if (previousSplitDistance + currentPoint.distance >= distance) { + if (currentPoint.distance >= distance || Math.abs(totalDistance - distance) < 0.1) { wpt = currentPoint; break; }