Fix colorization when speed was derived from timestamps
This commit is contained in:
parent
b36d5a92d8
commit
241a2387b1
3 changed files with 45 additions and 31 deletions
|
@ -4,6 +4,7 @@ import net.osmand.GPXUtilities;
|
|||
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;
|
||||
|
@ -30,6 +31,8 @@ public class RouteColorize {
|
|||
public static final int RED = rgbaToDecimal(243, 55, 77, 255);
|
||||
public static final int[] colors = new int[] {GREEN, YELLOW, RED};
|
||||
|
||||
private static final int MAX_SLOPE_VALUE = 25;
|
||||
|
||||
public enum ColorizationType {
|
||||
ELEVATION,
|
||||
SPEED,
|
||||
|
@ -75,7 +78,7 @@ public class RouteColorize {
|
|||
/**
|
||||
* @param type ELEVATION, SPEED, SLOPE
|
||||
*/
|
||||
public RouteColorize(int zoom, GPXUtilities.GPXFile gpxFile, ColorizationType type) {
|
||||
public RouteColorize(int zoom, GPXUtilities.GPXFile gpxFile, ColorizationType type, float maxProfileSpeed) {
|
||||
|
||||
if (!gpxFile.hasTrkPt()) {
|
||||
LOG.warn("GPX file is not consist of track points");
|
||||
|
@ -85,21 +88,27 @@ public class RouteColorize {
|
|||
List<Double> latList = new ArrayList<>();
|
||||
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) {
|
||||
latList.add(p.lat);
|
||||
lonList.add(p.lon);
|
||||
if (type == ColorizationType.SPEED) {
|
||||
valList.add(p.speed);
|
||||
valList.add((double) analysis.speedData.get(wptIdx).speed);
|
||||
} else {
|
||||
valList.add(p.ele);
|
||||
valList.add((double) analysis.elevationData.get(wptIdx).elevation);
|
||||
}
|
||||
wptIdx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.zoom = zoom;
|
||||
colorizationType = type;
|
||||
latitudes = listToArray(latList);
|
||||
longitudes = listToArray(lonList);
|
||||
|
||||
|
@ -108,9 +117,8 @@ public class RouteColorize {
|
|||
} else {
|
||||
values = listToArray(valList);
|
||||
}
|
||||
|
||||
calculateMinMaxValue();
|
||||
colorizationType = type;
|
||||
maxValue = getMaxValue(colorizationType, analysis, minValue, maxProfileSpeed);
|
||||
checkPalette();
|
||||
sortPalette();
|
||||
}
|
||||
|
@ -194,7 +202,7 @@ public class RouteColorize {
|
|||
return rgbaToDecimal((int) resultRed, (int) resultGreen, (int) resultBlue, (int) resultAlpha);
|
||||
}
|
||||
}
|
||||
return getDefaultColor();
|
||||
return getTransparentColor();
|
||||
}
|
||||
|
||||
public void setPalette(double[][] palette) {
|
||||
|
@ -209,12 +217,12 @@ public class RouteColorize {
|
|||
}
|
||||
setPalette(new double[][] {
|
||||
{minValue, gradientPalette[0]},
|
||||
{colorizationType == ColorizationType.SLOPE ? 0 : (minValue + maxValue) / 2, gradientPalette[1]},
|
||||
{(minValue + maxValue) / 2, gradientPalette[1]},
|
||||
{maxValue, gradientPalette[2]}
|
||||
});
|
||||
}
|
||||
|
||||
private int getDefaultColor() {
|
||||
private int getTransparentColor() {
|
||||
return rgbaToDecimal(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -295,7 +303,7 @@ public class RouteColorize {
|
|||
|
||||
double[][] defaultPalette = {
|
||||
{minValue, GREEN},
|
||||
{colorizationType == ColorizationType.SLOPE ? 0 : (minValue + maxValue) / 2, YELLOW},
|
||||
{(minValue + maxValue) / 2, YELLOW},
|
||||
{maxValue, RED}
|
||||
};
|
||||
palette = defaultPalette;
|
||||
|
@ -397,6 +405,20 @@ public class RouteColorize {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static double getMinValue(ColorizationType type, GPXUtilities.GPXTrackAnalysis analysis) {
|
||||
return type == ColorizationType.ELEVATION ? analysis.minElevation : 0.0;
|
||||
}
|
||||
|
||||
public static double getMaxValue(ColorizationType type, GPXUtilities.GPXTrackAnalysis analysis, double minValue, double maxProfileSpeed) {
|
||||
if (type == ColorizationType.SPEED) {
|
||||
return Math.max(analysis.maxSpeed, maxProfileSpeed);
|
||||
} else if (type == ColorizationType.ELEVATION) {
|
||||
return Math.max(analysis.maxElevation, minValue + 50);
|
||||
} else {
|
||||
return MAX_SLOPE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateMinMaxValue() {
|
||||
if (values.length == 0)
|
||||
return;
|
||||
|
@ -457,5 +479,4 @@ public class RouteColorize {
|
|||
this.val = val;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.router.RouteColorize;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -42,8 +43,9 @@ public class GradientCard extends BaseCard {
|
|||
AndroidUiHelper.updateVisibility(view, true);
|
||||
TextView minValue = view.findViewById(R.id.min_value);
|
||||
TextView maxValue = view.findViewById(R.id.max_value);
|
||||
float min = getMinValue();
|
||||
float max = getMaxValue(min);
|
||||
double min = RouteColorize.getMinValue(selectedScaleType.toColorizationType(), gpxTrackAnalysis);
|
||||
double max = RouteColorize.getMaxValue(selectedScaleType.toColorizationType(),
|
||||
gpxTrackAnalysis, min, app.getSettings().getApplicationMode().getMaxSpeed());
|
||||
minValue.setText(formatValue(min));
|
||||
maxValue.setText(formatValue(max));
|
||||
}
|
||||
|
@ -53,27 +55,13 @@ public class GradientCard extends BaseCard {
|
|||
updateContent();
|
||||
}
|
||||
|
||||
private float getMinValue() {
|
||||
return (float) (selectedScaleType == GradientScaleType.ALTITUDE ? gpxTrackAnalysis.minElevation : 0.0);
|
||||
}
|
||||
|
||||
private float getMaxValue(float minValue) {
|
||||
if (selectedScaleType == GradientScaleType.SPEED) {
|
||||
return (Math.max(gpxTrackAnalysis.maxSpeed, app.getSettings().getApplicationMode().getMaxSpeed()));
|
||||
} else if (selectedScaleType == GradientScaleType.ALTITUDE) {
|
||||
return (float) Math.max(gpxTrackAnalysis.maxElevation, minValue + 50);
|
||||
} else {
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence formatValue(float value) {
|
||||
private CharSequence formatValue(double value) {
|
||||
if (selectedScaleType == GradientScaleType.ALTITUDE) {
|
||||
return OsmAndFormatter.getFormattedAlt(value, app);
|
||||
} else if (selectedScaleType == GradientScaleType.SLOPE) {
|
||||
return (int) value + " %";
|
||||
}
|
||||
String speed = OsmAndFormatter.getFormattedSpeed(value, app);
|
||||
String speed = OsmAndFormatter.getFormattedSpeed((float) value, app);
|
||||
String speedUnit = app.getSettings().SPEED_SYSTEM.get().toShortString(app);
|
||||
Spannable formattedSpeed = new SpannableString(speed);
|
||||
formattedSpeed.setSpan(
|
||||
|
|
|
@ -684,11 +684,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
|
|||
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
|
||||
GradientScaleType scaleType = getGradientScaleType(gpxFile);
|
||||
List<RouteColorize.RouteColorizationPoint> colorsOfPoints = null;
|
||||
if (scaleType != null) {
|
||||
RouteColorize colorize = new RouteColorize(view.getZoom(), gpxFile, scaleType.toColorizationType());
|
||||
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());
|
||||
colorize.setPalette(getColorizationPalette(gpxFile, scaleType));
|
||||
colorsOfPoints = colorize.getResult(false);
|
||||
}
|
||||
|
||||
int startIdx = 0;
|
||||
for (TrkSegment ts : segments) {
|
||||
String width = getTrackWidthName(gpxFile, defaultTrackWidthPref.get());
|
||||
|
|
Loading…
Reference in a new issue