Skip to content

Commit

Permalink
Implement gpxColors by difficulty/scale tags
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Jan 13, 2025
1 parent 4a301a7 commit ef1731f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
3 changes: 2 additions & 1 deletion OsmAnd/src/net/osmand/plus/track/clickable/ClickableWay.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint;
import net.osmand.shared.gpx.GpxFile;
import net.osmand.shared.gpx.primitives.WptPt;
import net.osmand.util.Algorithms;

public class ClickableWay {
private final long osmId;
Expand Down Expand Up @@ -34,7 +35,7 @@ public SelectedGpxPoint getSelectedGpxPoint() {
}

public String getWayName() {
return name != null ? name : Long.toString(osmId);
return Algorithms.isEmpty(name) ? Long.toString(osmId) : name;
}

public String toString() {
Expand Down
44 changes: 41 additions & 3 deletions OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,24 @@
import gnu.trove.list.array.TIntArrayList;

public class ClickableWayLoader {
public static final Set<String> clickableTags = Set.of("piste:type", "mtb:scale", "dirtbike:scale");
public static final Set<String> clickableTags = Set.of("piste:type", "piste:difficulty", "mtb:scale", "dirtbike:scale");
public static final Map<String, String> forbiddenTags = Map.of("area", "yes", "access", "no");
public static final Map<String, String> gpxColors = Map.ofEntries(
Map.entry("0", "brown"),
Map.entry("1", "green"),
Map.entry("2", "blue"),
Map.entry("3", "red"),
Map.entry("4", "black"),
Map.entry("5", "black"),
Map.entry("6", "black"),
Map.entry("novice", "green"),
Map.entry("easy", "blue"),
Map.entry("intermediate", "red"),
Map.entry("advanced", "black"),
Map.entry("expert", "black"),
Map.entry("freeride", "yellow")
// others are default (red)
);

private final OsmandApplication app;
private final ClickableWayActivator activator;
Expand Down Expand Up @@ -91,6 +107,8 @@ private ClickableWay searchClickableWay(LatLon searchLatLon, int searchRadius,

if (!Algorithms.isEmpty(name)) {
gpxFile.getMetadata().setName(name);
} else {
gpxFile.getMetadata().setName(Long.toString(osmId));
}

RouteActivityHelper helper = app.getRouteActivityHelper();
Expand All @@ -103,7 +121,7 @@ private ClickableWay searchClickableWay(LatLon searchLatLon, int searchRadius,
}
}

gpxFile.getExtensionsToWrite().putAll(tags); // TODO check prefix, check /:/ in tag
gpxFile.getExtensionsToWrite().putAll(tags);

TrkSegment trkSegment = new TrkSegment();
for (int i = 0; i < Math.min(xPoints.size(), yPoints.size()); i++) {
Expand All @@ -117,9 +135,14 @@ private ClickableWay searchClickableWay(LatLon searchLatLon, int searchRadius,
track.getSegments().add(trkSegment);
gpxFile.setTracks(List.of(track)); // immutable

String color = getGpxColorByTags(tags);
if (color != null) {
System.err.printf("XXX color (%s)\n", color);
gpxFile.setColor(color);
}

// TODO check unique gpx
// TODO cache <id, GpxFile>
// TODO gpx colors by difficulty
// TODO close previous on open new
// TODO fetch elevation data from routing-section
// TODO calc distance stats, elevation stats, etc (automatically if data exists)
Expand All @@ -128,6 +151,21 @@ private ClickableWay searchClickableWay(LatLon searchLatLon, int searchRadius,
return new ClickableWay(gpxFile, osmId, name, searchLatLon);
}

@Nullable
private String getGpxColorByTags(Map <String, String> tags) {
for (String t : clickableTags) {
String val = tags.get(t);
if (val != null) {
for (Map.Entry<String, String> matchColor : gpxColors.entrySet()) {
if (val.contains(matchColor.getKey())) {
return matchColor.getValue();
}
}
}
}
return null;
}

private int calcSearchRadius(TIntArrayList x, TIntArrayList y) {
QuadRect bbox = new QuadRect();
for (int i = 0; i < Math.min(x.size(), y.size()); i++) {
Expand Down

0 comments on commit ef1731f

Please sign in to comment.