Fixes after review
This commit is contained in:
parent
6cfc02979f
commit
d8ddb71742
2 changed files with 34 additions and 15 deletions
|
@ -1,10 +1,13 @@
|
|||
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.osm.edit.Node;
|
||||
import net.osmand.osm.edit.OsmMapUtils;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -78,7 +81,7 @@ public class RouteColorize {
|
|||
/**
|
||||
* @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()) {
|
||||
LOG.warn("GPX file is not consist of track points");
|
||||
|
@ -89,12 +92,10 @@ public class RouteColorize {
|
|||
List<Double> lonList = 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;
|
||||
for (GPXUtilities.Track t : gpxFile.tracks) {
|
||||
for (GPXUtilities.TrkSegment ts : t.segments) {
|
||||
for (GPXUtilities.WptPt p : ts.points) {
|
||||
for (Track t : gpxFile.tracks) {
|
||||
for (TrkSegment ts : t.segments) {
|
||||
for (WptPt p : ts.points) {
|
||||
latList.add(p.lat);
|
||||
lonList.add(p.lon);
|
||||
if (type == ColorizationType.SPEED) {
|
||||
|
@ -405,11 +406,11 @@ public class RouteColorize {
|
|||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
return Math.max(analysis.maxSpeed, maxProfileSpeed);
|
||||
} else if (type == ColorizationType.ELEVATION) {
|
||||
|
|
|
@ -680,16 +680,15 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
|
|||
|
||||
private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas,
|
||||
RotatedTileBox tileBox, DrawSettings settings) {
|
||||
OsmandApplication app = view.getApplication();
|
||||
GPXFile gpxFile = selectedGpxFile.getGpxFile();
|
||||
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
|
||||
GradientScaleType scaleType = getGradientScaleType(gpxFile);
|
||||
List<RouteColorize.RouteColorizationPoint> colorsOfPoints = null;
|
||||
boolean needCalculateColors = scaleType != null && segments.get(0).points.get(0)
|
||||
.getColor(scaleType.toColorizationType()) == 0;
|
||||
|
||||
if (scaleType != null && currentTrack || needCalculateColors) {
|
||||
RouteColorize colorize = new RouteColorize(view.getZoom(), gpxFile,
|
||||
scaleType.toColorizationType(), view.getApplication().getSettings().getApplicationMode().getMaxSpeed());
|
||||
if (needCalculatePointsColors(segments, scaleType)) {
|
||||
RouteColorize colorize = new RouteColorize(view.getZoom(), gpxFile, selectedGpxFile.getTrackAnalysis(app),
|
||||
scaleType.toColorizationType(), app.getSettings().getApplicationMode().getMaxSpeed());
|
||||
colorize.setPalette(getColorizationPalette(gpxFile, scaleType));
|
||||
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) {
|
||||
int pointsSize = segment.points.size();
|
||||
RouteColorize.RouteColorizationPoint startColor = colors.get(startIdx);
|
||||
|
|
Loading…
Reference in a new issue