Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display all GPX tags in Track Menu, fix broken Ski routes switch, fix minor bugs #21790

Merged
merged 32 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b374d78
Assume route_piste as a key for SKI routes (draft)
RZR-UA Jan 22, 2025
7b0004f
Merge branch 'master' into rzr-ski-piste
RZR-UA Jan 23, 2025
5b5b4c9
Consider only CLICKABLE_TAGS for activity type
RZR-UA Jan 23, 2025
8ec0da9
Improve FORBIDDEN_TAGS for relations, add way_id
RZR-UA Jan 23, 2025
46f3850
Fix networkRouteKeyTags with ":" chars in the name
RZR-UA Jan 23, 2025
5fd3c95
Use "Information" instead of "Route information"
RZR-UA Jan 23, 2025
c7629a7
Use OsmRouteType.name when no relation_id exists
RZR-UA Jan 23, 2025
1eb24f5
Display and save ClickableWay tags using RouteKey
RZR-UA Jan 23, 2025
32cc422
Improve ClickableWay.getWayName() [cherry-pick]
RZR-UA Jan 22, 2025
420fc71
Add SAVE_TAGS_AS_ROUTE_KEY flag to ClickableWay
RZR-UA Jan 24, 2025
4ebc111
Turn MetadataExtensionsCard into TrackExtensionsCard
RZR-UA Jan 24, 2025
211b5ff
Process XML_COLON at stage of reading GPX extensions
RZR-UA Jan 24, 2025
998d3b2
Get back TrackMenuFragment changes (remove soon)
RZR-UA Jan 26, 2025
a928a79
Use RouteInfoCard to show gpx/metadata extensions
RZR-UA Jan 26, 2025
b11e869
Revert "Turn MetadataExtensionsCard into TrackExtensionsCard"
RZR-UA Jan 26, 2025
d15cee5
Replace MetadataExtensionsCard with RouteInfoCard
RZR-UA Jan 26, 2025
c621088
Use new isGpxAppearanceTag to hide appearance tags
RZR-UA Jan 26, 2025
d5dab31
Comment unused TRACK_DELETED_KEY const
RZR-UA Jan 26, 2025
44767b7
Merge branch 'master' into rzr-ski-piste
RZR-UA Jan 26, 2025
3c4d001
Remove route_id from TRANSLATABLE_KEYS (rare usage)
RZR-UA Jan 27, 2025
b408c07
Simplify with getOsmIdFromPrefixedRouteId
RZR-UA Jan 27, 2025
20eae03
Use updateVisibility()
RZR-UA Jan 27, 2025
aedeefb
Get rid of SAVE_TAGS_AS_ROUTE_KEY
RZR-UA Jan 27, 2025
dd405e2
Refactor gpxAppearanceTags in GpxAppearanceInfo
RZR-UA Jan 27, 2025
bd4e595
Merge branch 'master' into rzr-ski-piste
RZR-UA Jan 27, 2025
c2c4291
Fix OOB for tags without values, avoid empty cards
RZR-UA Jan 27, 2025
33355ac
Use getFromTo() of the route if no name/ref found
RZR-UA Jan 28, 2025
fdb111b
Experiment to diminish addOsmRoutes by relation_id
RZR-UA Jan 28, 2025
45f2f05
Revert "Experiment to diminish addOsmRoutes by relation_id"
RZR-UA Jan 30, 2025
0113b74
Ignore click-to-propagaded-way (REQUIRED_TAGS_ANY)
RZR-UA Jan 30, 2025
13ec1a0
Add piste:name to REQUIRED_TAGS_ANY
RZR-UA Jan 30, 2025
2fbbd67
Merge branch 'master' into rzr-ski-piste
RZR-UA Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions OsmAnd-java/src/main/java/net/osmand/osm/OsmRouteType.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public class OsmRouteType {
public static final OsmRouteType FERRY = createType("ferry").reg();
public static final OsmRouteType FOOT = createType("foot").reg();
public static final OsmRouteType LIGHT_RAIL = createType("light_rail").reg();
public static final OsmRouteType PISTE = createType("piste").reg();
public static final OsmRouteType RAILWAY = createType("railway").reg();
public static final OsmRouteType SKI = createType("ski").renderingPropertyAttr(PISTE_ROUTES).reg();
public static final OsmRouteType SKI = createType("piste").renderingPropertyAttr(PISTE_ROUTES).reg();
public static final OsmRouteType ALPINE = createType("alpine").renderingPropertyAttr(ALPINE_HIKING).reg();
public static final OsmRouteType FITNESS = createType("fitness").renderingPropertyAttr(FITNESS_TRAILS).reg();
public static final OsmRouteType INLINE_SKATES = createType("inline_skates").reg();
Expand All @@ -62,6 +61,7 @@ public class OsmRouteType {
public static final OsmRouteType TRAM = createType("tram").reg();
public static final OsmRouteType TROLLEYBUS = createType("trolleybus").reg();
public static final OsmRouteType CLIMBING = createType("climbing").renderingPropertyAttr(CLIMBING_ROUTES).reg();
public static final OsmRouteType UNKNOWN = createType("unknown").reg();

// less specific bottom order
private final String name;
Expand Down Expand Up @@ -157,7 +157,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 @@ -306,8 +307,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 @@ -323,6 +325,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
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,11 @@ public String getRouteName(String localeId, boolean transliteration) {
return transliteration ? TransliterationHelper.transliterate(name) : name;
}
name = getValue("ref");
return !name.isEmpty() ? name : getRelationID();
if (!name.isEmpty()) {
return name;
}
name = getRelationID();
return !name.isEmpty() ? name : this.type.getName();
}

public String getRelationID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ object GpxUtilities {
val tagsBundle = StringBundle()
tagsBundle.putString("type", gpxFile.networkRouteKeyTags.get("type"))
for ((key, value) in gpxFile.networkRouteKeyTags) {
tagsBundle.putString(key, value)
val attributeToXml = key.replace(":", XML_COLON)
tagsBundle.putString(attributeToXml, value)
}
val routeKeyBundle = mutableListOf<StringBundle>()
routeKeyBundle.add(tagsBundle)
Expand Down Expand Up @@ -1466,7 +1467,7 @@ object GpxUtilities {

private fun getExtensionsSupportedTag(tag: String): String {
val supportedTag = SUPPORTED_EXTENSION_TAGS[tag]
return supportedTag ?: tag
return supportedTag ?: tag.replace(XML_COLON, ":")
}

private fun parseRouteKeyAttributes(parser: XmlPullParser): Map<String, String> {
Expand All @@ -1477,7 +1478,8 @@ object GpxUtilities {
if (!bundle.isEmpty()) {
for (item in bundle.getMap().values) {
if (item.type == StringBundle.ItemType.STRING) {
networkRouteKeyTags[item.name] = item.value as String
val attributeFromXml = item.name.replace(XML_COLON, ":")
networkRouteKeyTags[attributeFromXml] = item.value as String
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion OsmAnd/res/layout/gpx_route_info_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_small"
android:text="@string/route_info"
android:text="@string/poi_information"
android:textColor="?android:textColorSecondary"
app:typefaceWeight="medium" />

Expand Down
2 changes: 1 addition & 1 deletion OsmAnd/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4254,7 +4254,7 @@ Download tile maps directly, or copy them as SQLite database files to OsmAnd\'s
<string name="notes">A/V notes</string>
<string name="online_map">Online map</string>
<string name="roads_only">Roads only</string>
<string name="rendering_attr_pisteRoutes_name">Ski slopes</string>
<string name="rendering_attr_pisteRoutes_name">Ski routes</string>
<string name="free">Free %1$s </string>
<string name="device_memory">Device memory</string>
<string name="rendering_attr_pisteGrooming_name">Piste grooming</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void collectOrderedRouteTypesForProfile() {
ROAD.getName(), DETOUR.getName(), BICYCLE.getName(), MOUNTAINBIKE.getName());
addRouteTypes(ApplicationMode.PUBLIC_TRANSPORT,
BUS.getName(), TRAM.getName(), TROLLEYBUS.getName(), SUBWAY.getName(), TRAIN.getName(),
RAILWAY.getName(), TRACKS.getName(), LIGHT_RAIL.getName(), PISTE.getName());
RAILWAY.getName(), TRACKS.getName(), LIGHT_RAIL.getName());
addRouteTypes(ApplicationMode.TRAIN,
TRAIN.getName(), LIGHT_RAIL.getName(), TRACKS.getName(), SUBWAY.getName(), TRAM.getName());
addRouteTypes(ApplicationMode.BOAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ public static GpxAppearanceInfo fromJson(@NonNull JSONObject json) {
return hasAnyParam ? gpxAppearanceInfo : null;
}

public static boolean isGpxAppearanceTag(String tag) {
RZR-UA marked this conversation as resolved.
Show resolved Hide resolved
Object[] testValues = { "1", 1, 1L, 1D, true };
for (Object value : testValues) {
try {
JSONObject json = new JSONObject();
json.put(tag, value); // try types
if (fromJson(json) != null) {
return true;
}
} catch (JSONException ignored) { }
}
return false;
}

private static GradientScaleType getScaleType(String name) {
if (!Algorithms.isEmpty(name)) {
try {
Expand Down
41 changes: 0 additions & 41 deletions OsmAnd/src/net/osmand/plus/track/cards/MetadataExtensionsCard.java

This file was deleted.

52 changes: 43 additions & 9 deletions OsmAnd/src/net/osmand/plus/track/cards/RouteInfoCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.plus.settings.backend.backup.GpxAppearanceInfo;
import net.osmand.shared.gpx.GpxFile;
import net.osmand.shared.gpx.primitives.WptPt;
import net.osmand.osm.AbstractPoiType;
Expand Down Expand Up @@ -39,28 +42,36 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONTEXT_MENU_LINKS_ID;
import static net.osmand.data.Amenity.DESCRIPTION;
import static net.osmand.data.Amenity.NAME;
import static net.osmand.shared.gpx.GpxUtilities.ACTIVITY_TYPE;

public class RouteInfoCard extends MapBaseCard {
import org.apache.commons.logging.Log;

private static final String OSM_RELATION_URL = "https://www.openstreetmap.org/relation/";
public class RouteInfoCard extends MapBaseCard {
public static final Set<String> HIDDEN_GPX_TAGS = Set.of(ACTIVITY_TYPE, NAME, DESCRIPTION);
public static final String OSM_RELATION_URL = "https://www.openstreetmap.org/relation/";
public 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);
}


private final RouteKey routeKey;
private final GpxFile gpxFile;
private static final Log log = PlatformUtil.getLog(RouteInfoCard.class);

public RouteInfoCard(
@NonNull MapActivity activity,
Expand All @@ -82,11 +93,13 @@ public void updateContent() {
LinearLayout container = view.findViewById(R.id.items_container);
container.removeAllViews();

String routeTypeToDisplay = AndroidUtils.getActivityTypeTitle(app, routeKey.type);
addInfoRow(container, app.getString(R.string.layer_route), routeTypeToDisplay, false, false);
if (routeKey.type != OsmRouteType.UNKNOWN) {
String routeTypeToDisplay = AndroidUtils.getActivityTypeTitle(app, routeKey.type);
addInfoRow(container, app.getString(R.string.layer_route), routeTypeToDisplay, false, false);
}

int addedRows = 0;
for (TagsRow row : getRows()) {

LinearLayout expandableView = null;
int tagsCount = row.tags.size();

Expand All @@ -96,6 +109,7 @@ public void updateContent() {

ViewGroup tagContainer = tagIndex == 0 ? container : expandableView;
View view = addInfoRow(tagContainer, tag);
addedRows++;

if (tagIndex == 0 && tagsCount > 1) {
expandableView = createExpandableView();
Expand All @@ -104,6 +118,10 @@ public void updateContent() {
}
}
}

if (addedRows == 0) {
view.setVisibility(View.GONE);
}
RZR-UA marked this conversation as resolved.
Show resolved Hide resolved
}

@NonNull
Expand All @@ -115,8 +133,14 @@ private List<TagsRow> getRows() {
String key = routeKey.getKeyFromTag(tag);
String value = routeKey.getValue(key);

if (key.equals("name") || key.equals("type") || key.contains("osmc")) {
continue;
if (routeKey.type != OsmRouteType.UNKNOWN) {
if (key.equals("name") || key.equals("type") || key.contains("osmc")) {
continue;
}
} else {
if (HIDDEN_GPX_TAGS.contains(key) || GpxAppearanceInfo.isGpxAppearanceTag(key)) {
continue;
}
}

RouteTag routeTag = new RouteTag(key, value);
Expand Down Expand Up @@ -171,6 +195,16 @@ 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));
} else if ("route_id".equals(tag.key) && tag.value.startsWith(Amenity.ROUTE_ID_OSM_PREFIX)) {
try {
long osmId = Long.parseLong(tag.value.replace(Amenity.ROUTE_ID_OSM_PREFIX, ""));
RZR-UA marked this conversation as resolved.
Show resolved Hide resolved
setupClickableContent(view, v -> AndroidUtils.openUrl(activity, OSM_RELATION_URL + osmId, nightMode));
} catch (NumberFormatException e) {
log.warn("RouteInfoCard: unable to parse osmId from route_id " + tag.value);
}
}
return view;
}
Expand Down Expand Up @@ -245,7 +279,7 @@ private List<LatLon> collectTrackPoints() {
}

private boolean shouldAddRow(@NonNull String key) {
if ("relation_id".equals(key)) {
if ("relation_id".equals(key) || "way_id".equals(key)) {
return PluginsHelper.isEnabled(OsmEditingPlugin.class);
}
return true;
Expand Down
7 changes: 6 additions & 1 deletion OsmAnd/src/net/osmand/plus/track/clickable/ClickableWay.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public String getGpxFileName() {

@NonNull
public String getWayName() {
return Algorithms.isEmpty(name) ? Long.toString(osmId) : name;
if (!Algorithms.isEmpty(name)) {
return name;
} else {
String altName = gpxFile.getExtensionsToRead().get("ref");
return altName != null ? altName : Long.toString(osmId);
}
}

@Override
Expand Down
Loading
Loading