From 57b4d9bca3a61557d0174c8bcb8826893b4bee06 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 15 Jan 2025 11:34:54 +0100 Subject: [PATCH] Display individual line width from GPX trk/trkseg --- .../kotlin/net/osmand/shared/gpx/GpxFile.kt | 13 ++++--------- .../kotlin/net/osmand/shared/gpx/GpxUtilities.kt | 1 + .../osmand/shared/gpx/primitives/GpxExtensions.kt | 8 ++++++++ .../src/net/osmand/plus/views/layers/GPXLayer.java | 10 ++++++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt index eb8330f169e4..8e87768f1961 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt @@ -492,13 +492,16 @@ class GpxFile : GpxExtensions { val tpoints = mutableListOf() 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) } } } @@ -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 } diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt index 85cb835a4dde..19fb11b27aab 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt @@ -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" diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt index aa771f6ae155..6105be88a198 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt @@ -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 + } + } } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index 9aecff8c587b..9aacd8bbc90d 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -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 { @@ -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()) {