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

Improve display names of route relations #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static void unregisterFormatHook(NameFormatterHook hook) {
private static final String[] DEFAULT_NAMING_TAGS_FOR_RELATIONS = {
"name",
"ref",
"from-to",
//
"amenity",
"landuse",
Expand Down Expand Up @@ -357,7 +358,7 @@ private static StringBuilder formatRelationNameAndType(IRelation<?> relation, St
result.append(" (").append(relationName).append(", ");
} else {
preset.nameTemplate.appendText(result, (TemplateEngineDataProvider) relation);
result.append('(');
result.append(" (");
}
return result;
}
Expand Down Expand Up @@ -412,6 +413,10 @@ public Comparator<IRelation<?>> getRelationComparator() {
private static String getRelationTypeName(IRelation<?> relation) {
// see https://josm.openstreetmap.de/browser/osm/applications/editors/josm/i18n/specialmessages.java
String name = trc("Relation type", relation.get("type"));
if (relation.hasTag("type", "route") && relation.hasKey("route")) {
String route = trc("Route type", relation.get("route"));
name = route + " " + name;
}
if (name == null) {
name = relation.hasKey("public_transport") ? tr("public transport") : null;
}
Expand Down Expand Up @@ -447,6 +452,12 @@ private static String getRelationTypeName(IRelation<?> relation) {
private static String getNameTagValue(IRelation<?> relation, String nameTag) {
if ("name".equals(nameTag)) {
return formatLocalName(relation);
} else if ("from-to".equals(nameTag)) {
String from = trcLazy("from", I18n.escape(relation.get("from")));
String to = trcLazy("to", I18n.escape(relation.get("to")));
if (from != null || to != null)
return (from != null ? from : "?") + "-" + (to != null ? to : "?");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend it to return -<TO> when from is null and <FROM>- when to is null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This intends (and I think implements) to return ?-<TO> when from is null and <FROM>-? when to is null.

return null;
} else if (":LocationCode".equals(nameTag)) {
return relation.keys()
.filter(m -> m.endsWith(nameTag))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,16 @@ void testRelationName() {
getFormattedRelationName("X=Y"));
assertEquals("relation (\"Foo\", 0 members)",
getFormattedRelationName("name=Foo"));
assertEquals("route (\"123\", 0 members)",
assertEquals("tram route (\"123\", 0 members)",
getFormattedRelationName("type=route route=tram ref=123"));
assertEquals("bus route (\"foo\", 0 members)",
getFormattedRelationName("type=route route=bus from=a to=b name=foo"));
assertEquals("bus route (\"a-b\", 0 members)",
getFormattedRelationName("type=route route=bus from=a to=b"));
assertEquals("bus route (\"a-?\", 0 members)",
getFormattedRelationName("type=route route=bus from=a"));
assertEquals("bus route (\"?-b\", 0 members)",
getFormattedRelationName("type=route route=bus to=b"));
assertEquals("multipolygon (\"building\", 0 members)",
getFormattedRelationName("type=multipolygon building=yes"));
assertEquals("multipolygon (\"123\", 0 members)",
Expand Down