Skip to content

Commit

Permalink
Display individual line width from GPX trk/trkseg
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Jan 15, 2025
1 parent 90f5d64 commit 57b4d9b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,16 @@ class GpxFile : GpxExtensions {
val tpoints = mutableListOf<TrkSegment>()
for (track in tracks) {
val trackColor = track.getColor(getColor(null))
val trackWidth = track.getWidth(null)
for (segment in track.segments) {
val segmentColor = segment.getColor(trackColor)
val segmentWidth = segment.getWidth(trackWidth)
if (!segment.generalSegment && segment.points.isNotEmpty()) {
val ts = TrkSegment()
tpoints.add(ts)
ts.points.addAll(segment.points)
ts.setColor(segmentColor)
ts.setWidth(segmentWidth)
ts.points.addAll(segment.points)
}
}
}
Expand Down Expand Up @@ -618,14 +621,6 @@ class GpxFile : GpxExtensions {
getExtensionsToWrite()["split_interval"] = splitInterval.toString()
}

fun getWidth(defWidth: String?): String? {
return extensions?.get("width") ?: defWidth
}

fun setWidth(width: String) {
getExtensionsToWrite()["width"] = width
}

fun isShowArrowsSet(): Boolean {
return extensions?.containsKey("show_arrows") ?: false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object GpxUtilities {
const val ICON_NAME_EXTENSION = "icon"
const val BACKGROUND_TYPE_EXTENSION = "background"
const val COLOR_NAME_EXTENSION = "color"
const val LINE_WIDTH_EXTENSION = "width"
const val PROFILE_TYPE_EXTENSION = "profile"
const val ADDRESS_EXTENSION = "address"
const val HIDDEN_EXTENSION = "hidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ open class GpxExtensions {
fun removeColor() {
getExtensionsToWrite().remove(GpxUtilities.COLOR_NAME_EXTENSION)
}

fun getWidth(defaultWidth: String?) = this.extensions?.get(GpxUtilities.LINE_WIDTH_EXTENSION) ?: defaultWidth

fun setWidth(width: String?) {
width?.let {
getExtensionsToWrite()[GpxUtilities.LINE_WIDTH_EXTENSION] = it
}
}
}
10 changes: 6 additions & 4 deletions OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1131,9 +1131,7 @@ private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox,
for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
GpxFile gpxFile = selectedGpxFile.getGpxFile();
String width = gpxAppearanceHelper.getTrackWidth(gpxFile, defaultWidthPref.get());
if (!cachedTrackWidth.containsKey(width)) {
cachedTrackWidth.put(width, null);
}
cachedTrackWidth.putIfAbsent(width, null);
if (selectedGpxFile.isShowCurrentTrack()) {
currentTrack = selectedGpxFile;
} else {
Expand Down Expand Up @@ -1212,9 +1210,13 @@ private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean c
renderedSegments = new HashSet<>();
renderedSegmentsCache.put(gpxFilePath, renderedSegments);
}
String width = gpxAppearanceHelper.getTrackWidth(gpxFile, defaultWidthPref.get());
String gpxWidth = gpxAppearanceHelper.getTrackWidth(gpxFile, defaultWidthPref.get());
for (int segmentIdx = 0; segmentIdx < segments.size(); segmentIdx++) {
TrkSegment ts = segments.get(segmentIdx);

String width = ts.getWidth(gpxWidth);
cachedTrackWidth.putIfAbsent(width, null);

int color = getTrackColor(gpxFile, ts.getColor(cachedColor));
boolean newTsRenderer = false;
if (ts.getRenderer() == null && !ts.getPoints().isEmpty()) {
Expand Down

0 comments on commit 57b4d9b

Please sign in to comment.