Fixes after review

This commit is contained in:
cepprice 2021-04-04 18:03:09 +05:00
parent 6cfc02979f
commit d8ddb71742
2 changed files with 34 additions and 15 deletions

View file

@ -1,10 +1,13 @@
package net.osmand.router; package net.osmand.router;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.Track;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OsmMapUtils; import net.osmand.osm.edit.OsmMapUtils;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -78,7 +81,7 @@ public class RouteColorize {
/** /**
* @param type ELEVATION, SPEED, SLOPE * @param type ELEVATION, SPEED, SLOPE
*/ */
public RouteColorize(int zoom, GPXUtilities.GPXFile gpxFile, ColorizationType type, float maxProfileSpeed) { public RouteColorize(int zoom, GPXFile gpxFile, GPXTrackAnalysis analysis, ColorizationType type, float maxProfileSpeed) {
if (!gpxFile.hasTrkPt()) { if (!gpxFile.hasTrkPt()) {
LOG.warn("GPX file is not consist of track points"); LOG.warn("GPX file is not consist of track points");
@ -89,12 +92,10 @@ public class RouteColorize {
List<Double> lonList = new ArrayList<>(); List<Double> lonList = new ArrayList<>();
List<Double> valList = new ArrayList<>(); List<Double> valList = new ArrayList<>();
GPXUtilities.GPXTrackAnalysis analysis = Algorithms.isEmpty(gpxFile.path) ?
gpxFile.getAnalysis(System.currentTimeMillis()) : gpxFile.getAnalysis(gpxFile.modifiedTime);
int wptIdx = 0; int wptIdx = 0;
for (GPXUtilities.Track t : gpxFile.tracks) { for (Track t : gpxFile.tracks) {
for (GPXUtilities.TrkSegment ts : t.segments) { for (TrkSegment ts : t.segments) {
for (GPXUtilities.WptPt p : ts.points) { for (WptPt p : ts.points) {
latList.add(p.lat); latList.add(p.lat);
lonList.add(p.lon); lonList.add(p.lon);
if (type == ColorizationType.SPEED) { if (type == ColorizationType.SPEED) {
@ -405,11 +406,11 @@ public class RouteColorize {
return result; return result;
} }
public static double getMinValue(ColorizationType type, GPXUtilities.GPXTrackAnalysis analysis) { public static double getMinValue(ColorizationType type, GPXTrackAnalysis analysis) {
return type == ColorizationType.ELEVATION ? analysis.minElevation : 0.0; return type == ColorizationType.ELEVATION ? analysis.minElevation : 0.0;
} }
public static double getMaxValue(ColorizationType type, GPXUtilities.GPXTrackAnalysis analysis, double minValue, double maxProfileSpeed) { public static double getMaxValue(ColorizationType type, GPXTrackAnalysis analysis, double minValue, double maxProfileSpeed) {
if (type == ColorizationType.SPEED) { if (type == ColorizationType.SPEED) {
return Math.max(analysis.maxSpeed, maxProfileSpeed); return Math.max(analysis.maxSpeed, maxProfileSpeed);
} else if (type == ColorizationType.ELEVATION) { } else if (type == ColorizationType.ELEVATION) {

View file

@ -680,16 +680,15 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas, private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas,
RotatedTileBox tileBox, DrawSettings settings) { RotatedTileBox tileBox, DrawSettings settings) {
OsmandApplication app = view.getApplication();
GPXFile gpxFile = selectedGpxFile.getGpxFile(); GPXFile gpxFile = selectedGpxFile.getGpxFile();
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay(); List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
GradientScaleType scaleType = getGradientScaleType(gpxFile); GradientScaleType scaleType = getGradientScaleType(gpxFile);
List<RouteColorize.RouteColorizationPoint> colorsOfPoints = null; List<RouteColorize.RouteColorizationPoint> colorsOfPoints = null;
boolean needCalculateColors = scaleType != null && segments.get(0).points.get(0)
.getColor(scaleType.toColorizationType()) == 0;
if (scaleType != null && currentTrack || needCalculateColors) { if (needCalculatePointsColors(segments, scaleType)) {
RouteColorize colorize = new RouteColorize(view.getZoom(), gpxFile, RouteColorize colorize = new RouteColorize(view.getZoom(), gpxFile, selectedGpxFile.getTrackAnalysis(app),
scaleType.toColorizationType(), view.getApplication().getSettings().getApplicationMode().getMaxSpeed()); scaleType.toColorizationType(), app.getSettings().getApplicationMode().getMaxSpeed());
colorize.setPalette(getColorizationPalette(gpxFile, scaleType)); colorize.setPalette(getColorizationPalette(gpxFile, scaleType));
colorsOfPoints = colorize.getResult(false); colorsOfPoints = colorize.getResult(false);
} }
@ -721,6 +720,25 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} }
} }
private boolean needCalculatePointsColors(List<TrkSegment> segments, GradientScaleType scaleType) {
if (scaleType == null) {
return false;
}
RouteColorize.ColorizationType colorizationType = scaleType.toColorizationType();
for (int segIdx = segments.size() - 1; segIdx >= 0; segIdx--) {
List<WptPt> pts = segments.get(segIdx).points;
if (!Algorithms.isEmpty(pts)) {
for (int wptIdx = pts.size() - 1; wptIdx >= 0; wptIdx--) {
WptPt pt = pts.get(wptIdx);
if (pt.getColor(colorizationType) == 0) {
return true;
}
}
}
}
return false;
}
private int setColorsToPoints(TrkSegment segment, List<RouteColorize.RouteColorizationPoint> colors, GradientScaleType scaleType, int startIdx) { private int setColorsToPoints(TrkSegment segment, List<RouteColorize.RouteColorizationPoint> colors, GradientScaleType scaleType, int startIdx) {
int pointsSize = segment.points.size(); int pointsSize = segment.points.size();
RouteColorize.RouteColorizationPoint startColor = colors.get(startIdx); RouteColorize.RouteColorizationPoint startColor = colors.get(startIdx);