Skip to content

Commit

Permalink
Replace osm_*_present tags with hasOsmRouteId()
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Dec 4, 2024
1 parent 9409b54 commit 33dfd0f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
6 changes: 6 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/data/Amenity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Amenity extends MapObject {
public static final String IS_AGGR_PART = "is_aggr_part";
public static final String CONTENT_JSON = "content_json";
public static final String ROUTE_ID = "route_id";
public static final String ROUTE_ID_OSM_PREFIX = "OSM";
public static final String ROUTE_SOURCE = "route_source";
public static final String ROUTE_NAME = "route_name";
public static final String COLOR = "color";
Expand Down Expand Up @@ -452,6 +453,11 @@ public String getRouteId() {
return getAdditionalInfo(ROUTE_ID);
}

public boolean hasOsmRouteId() {
String routeId = getRouteId();
return routeId != null && routeId.startsWith(ROUTE_ID_OSM_PREFIX);
}

public String getGpxFileName(String lang) {
final String gpxFileName = lang != null ? getName(lang) : getEnName(true);
if (!Algorithms.isEmpty(gpxFileName)) {
Expand Down
5 changes: 5 additions & 0 deletions OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public String getRouteId() {
return routeId;
}

public boolean hasOsmRouteId() {
String routeId = getRouteId();
return routeId != null && routeId.startsWith(Amenity.ROUTE_ID_OSM_PREFIX);
}

@NonNull
public String getGpxFileName() {
String gpxFileName = !Algorithms.isEmpty(title) ? title : routeId;
Expand Down
40 changes: 20 additions & 20 deletions OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ public class TravelObfHelper implements TravelHelper {
private final List<Pair<File, Amenity>> foundAmenities = new ArrayList<>();
public volatile int requestNumber = 0;

// Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way.
private static final Set<String> saveAsIsAmenityGpxTags = Set.of(
"route_id", "flexible_line_width", "translucent_line_colors", "shield_"
);
// Do not clutter GPX with tags that are always generated.
private static final Set<String> avoidAmenityGpxTags = Set.of(
private static final Set<String> doNotSaveAmenityGpxTags = Set.of(
"date", "distance", "route_name", "route_radius",
"avg_ele", "min_ele", "max_ele", "start_ele", "ele_graph", "diff_ele_up", "diff_ele_down",
"avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps"
);
// Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way.
private static final Set<String> keepAsIsAmenityGpxTags = Set.of(
"route_id", "flexible_line_width", "translucent_line_colors", "shield_"
);

public TravelObfHelper(OsmandApplication app) {
this.app = app;
Expand Down Expand Up @@ -1169,15 +1169,19 @@ public boolean publish(Amenity amenity) {
if (tag.startsWith(OBF_GPX_EXTENSION_TAG_PREFIX)) {
String gpxTag = tag.replaceFirst(OBF_GPX_EXTENSION_TAG_PREFIX, "");
gpxFileExtensions.put(gpxTag, value);
} else if (!avoidAmenityGpxTags.contains(tag)) {
String gpxTag = OSM_PREFIX + tag;
for (String prefix : keepAsIsAmenityGpxTags) {
} else if (!doNotSaveAmenityGpxTags.contains(tag)) {
boolean saveAsIs = false;
for (String prefix : saveAsIsAmenityGpxTags) {
if (tag.startsWith(prefix)) {
gpxTag = tag;
saveAsIs = true;
break;
}
}
gpxFileExtensions.put(gpxTag, value);
if (saveAsIs) {
gpxFileExtensions.put(tag, value);
} else if (amenity.hasOsmRouteId()) {
gpxFileExtensions.put(OSM_PREFIX + tag, value);
}
}
}
}
Expand Down Expand Up @@ -1205,8 +1209,10 @@ private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map<String, Stri
if (subType.startsWith(ROUTES_PREFIX)) {
String osmValue = amenity.getType().getPoiTypeByKeyName(subType).getOsmValue();
if (!Algorithms.isEmpty(osmValue)) {
gpxFileExtensions.put(OSM_PREFIX + "type", "route");
gpxFileExtensions.put(OSM_PREFIX + "route", osmValue);
if (amenity.hasOsmRouteId()) {
gpxFileExtensions.put(OSM_PREFIX + "type", "route");
gpxFileExtensions.put(OSM_PREFIX + "route", osmValue);
}
RouteActivityHelper helper = app.getRouteActivityHelper();
RouteActivity activity = helper.findActivityByTag(osmValue);
if (activity != null) {
Expand Down Expand Up @@ -1256,18 +1262,12 @@ private synchronized GpxFile buildGpxFile(@NonNull List<BinaryMapIndexReader> re
if (article instanceof TravelGpx) {
gpxFile = new GpxFile(Version.getFullVersion(app));
gpxFile.getMetadata().setName(Objects.requireNonNullElse(article.title, article.routeId)); // path is name
if (!Algorithms.isEmpty(article.title)) {
if (!Algorithms.isEmpty(article.title) && article.hasOsmRouteId()) {
gpxFileExtensions.putIfAbsent(OSM_PREFIX + "name", article.title);
}
if (!Algorithms.isEmpty(article.description)) {
gpxFile.getMetadata().setDesc(article.description);
}
final String[] cleanupByPresenceTags = { "ref", "name", "description" }; // osm_ref_present, etc
for (String tag : cleanupByPresenceTags) {
if (!gpxFileExtensions.containsKey("osm_" + tag + "_present")) {
gpxFileExtensions.remove(OSM_PREFIX + tag);
}
}
} else {
String description = article.getDescription();
String title = FileUtils.isValidFileName(description) ? description : article.getTitle();
Expand Down Expand Up @@ -1307,7 +1307,7 @@ private synchronized GpxFile buildGpxFile(@NonNull List<BinaryMapIndexReader> re
if (gpxFileExtensions.containsKey(GpxUtilities.ACTIVITY_TYPE)) {
gpxFile.getMetadata().getExtensionsToWrite()
.put(GpxUtilities.ACTIVITY_TYPE, gpxFileExtensions.get(GpxUtilities.ACTIVITY_TYPE));
gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // activities live in the metadata
gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // move activity to metadata
}
gpxFile.getExtensionsToWrite().putAll(gpxFileExtensions); // finally
}
Expand Down

0 comments on commit 33dfd0f

Please sign in to comment.