Skip to content

Commit

Permalink
Display and save ClickableWay tags using RouteKey
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Jan 23, 2025
1 parent c7629a7 commit 1eb24f5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 8 additions & 3 deletions OsmAnd-java/src/main/java/net/osmand/osm/OsmRouteType.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "mtb ride":
case "disused:mtb":
case "abandoned:mtb":
return MOUNTAINBIKE;
case "mtb:scale":
return MTB;
case "hiking":
case "route=hiking":
case "mountain hiking":
Expand Down Expand Up @@ -305,8 +306,9 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
case "лыжня":
case "nordic":
case "piste":
case "piste:type=nordic":
return WINTER;
case "piste:type":
case "piste:difficulty":
return SKI;
case "snowmobile=designated":
case "snowmobile=permissive":
case "snowmobile=yes":
Expand All @@ -322,6 +324,9 @@ public static OsmRouteType convertFromOsmGPXTag(String tg) {
return INLINE_SKATES;
case "fitness_trail":
return FITNESS;
case "dirtbike":
case "dirtbike:scale":
return DIRTBIKE;
}
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions OsmAnd/src/net/osmand/plus/track/cards/RouteInfoCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@
public class RouteInfoCard extends MapBaseCard {

private static final String OSM_RELATION_URL = "https://www.openstreetmap.org/relation/";
private static final String OSM_WAY_URL = "https://www.openstreetmap.org/way/";
private static final Map<String, Integer> TRANSLATABLE_KEYS = new HashMap<>();

static {
TRANSLATABLE_KEYS.put("name", R.string.shared_string_name);
TRANSLATABLE_KEYS.put("alt_name", R.string.shared_string_alt_name);
TRANSLATABLE_KEYS.put("symbol", R.string.shared_string_symbol);
TRANSLATABLE_KEYS.put("relation_id", R.string.shared_string_osm_id);
TRANSLATABLE_KEYS.put("way_id", R.string.shared_string_osm_id);
}


Expand Down Expand Up @@ -171,6 +173,9 @@ private View addInfoRow(@NonNull ViewGroup container, @NonNull RouteTag tag) {
} else if ("relation_id".equals(tag.key)) {
String url = OSM_RELATION_URL + formattedValue;
setupClickableContent(view, v -> AndroidUtils.openUrl(activity, url, nightMode));
} else if ("way_id".equals(tag.key)) {
String url = OSM_WAY_URL + formattedValue;
setupClickableContent(view, v -> AndroidUtils.openUrl(activity, url, nightMode));
}
return view;
}
Expand Down
13 changes: 11 additions & 2 deletions OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.osmand.shared.gpx.primitives.WptPt;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import net.osmand.osm.OsmRouteType;

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -127,20 +128,28 @@ private ClickableWay loadClickableWay(LatLon selectedLatLon, QuadRect bbox,
gpxFile.getMetadata().setName(Long.toString(osmId));
}

OsmRouteType compatibleOsmRouteType = null;
RouteActivityHelper helper = app.getRouteActivityHelper();
for (String clickableTag : CLICKABLE_TAGS) {
if (tags.containsKey(clickableTag)) {
RouteActivity activity = helper.findActivityByTag(clickableTag);
if (activity != null) {
String activityType = activity.getId();
compatibleOsmRouteType = OsmRouteType.getTypeFromTags(new String[]{clickableTag});
gpxFile.getMetadata().getExtensionsToWrite().put(GpxUtilities.ACTIVITY_TYPE, activityType);
break;
}
}
}

gpxFile.getExtensionsToWrite().putAll(tags);
gpxFile.getExtensionsToWrite().put("way_id", Long.toString(osmId));
if (compatibleOsmRouteType != null) {
gpxFile.addRouteKeyTags(tags);
gpxFile.addRouteKeyTags(Map.of("way_id", Long.toString(osmId)));
gpxFile.addRouteKeyTags(Map.of("type", compatibleOsmRouteType.getName()));
} else {
gpxFile.getExtensionsToWrite().putAll(tags);
gpxFile.getExtensionsToWrite().put("way_id", Long.toString(osmId));
}

TrkSegment trkSegment = new TrkSegment();
for (int i = 0; i < Math.min(xPoints.size(), yPoints.size()); i++) {
Expand Down

0 comments on commit 1eb24f5

Please sign in to comment.