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

Label route relations with directions and waypoints #8276

Merged
merged 1 commit into from
Jan 8, 2021
Merged
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
15 changes: 15 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,21 @@ en:
add_fields: "Add field:"
lock:
suggestion: 'The "{label}" field is locked because there is a Wikidata tag. You can delete it or edit the tags in the "Tags" section.'
display_name:
direction: "{direction}"
quincylvania marked this conversation as resolved.
Show resolved Hide resolved
from_to: "from {from} to {to}"
from_to_via: "from {from} to {to} via {via}"
network_direction: "{network} {direction}"
network_from_to: "{network} from {from} to {to}"
network_from_to_via: "{network} from {from} to {to} via {via}"
ref: "{ref}"
ref_direction: "{ref} {direction}"
ref_from_to: "{ref} from {from} to {to}"
ref_from_to_via: "{ref} from {from} to {to} via {via}"
network_ref: "{network} {ref}"
network_ref_direction: "{network} {ref} {direction}"
network_ref_from_to: "{network} {ref} from {from} to {to}"
network_ref_from_to_via: "{network} {ref} from {from} to {to} via {via}"
background:
title: Background
description: Background Settings
Expand Down
2 changes: 1 addition & 1 deletion dist/locales/en.min.json

Large diffs are not rendered by default.

37 changes: 32 additions & 5 deletions modules/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,42 @@ export function utilGetAllNodes(ids, graph) {
export function utilDisplayName(entity) {
var localizedNameKey = 'name:' + localizer.languageCode().toLowerCase();
var name = entity.tags[localizedNameKey] || entity.tags.name || '';
var network = entity.tags.cycle_network || entity.tags.network;
if (name) return name;

var tags = {
direction: entity.tags.direction,
from: entity.tags.from,
network: entity.tags.cycle_network || entity.tags.network,
ref: entity.tags.ref,
to: entity.tags.to,
via: entity.tags.via
};
var keyComponents = [];

if (tags.network) {
keyComponents.push('network');
}
if (tags.ref) {
keyComponents.push('ref');
}

if (!name && entity.tags.ref) {
name = entity.tags.ref;
if (network) {
name = network + ' ' + name;
// Routes may need more disambiguation based on direction or destination
if (entity.tags.route) {
if (tags.direction) {
keyComponents.push('direction');
} else if (tags.from && tags.to) {
keyComponents.push('from');
keyComponents.push('to');
if (tags.via) {
keyComponents.push('via');
}
}
}

if (keyComponents.length) {
name = t('inspector.display_name.' + keyComponents.join('_'), tags);
}

return name;
}

Expand Down
27 changes: 27 additions & 0 deletions test/spec/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,31 @@ describe('iD.util', function() {
expect(iD.utilUnicodeCharsTruncated('😎😬😆😵😴😄🙂🤔', 255)).to.eql('😎😬😆😵😴😄🙂🤔');
});
});

describe('utilDisplayName', function() {
it('returns the name if tagged with a name', function() {
expect(iD.utilDisplayName({tags: {name: 'East Coast Greenway'}})).to.eql('East Coast Greenway');
});
it('distinguishes unnamed features by ref', function() {
expect(iD.utilDisplayName({tags: {ref: '66'}})).to.eql('66');
quincylvania marked this conversation as resolved.
Show resolved Hide resolved
});
it('distinguishes unnamed features by network or cycle_network', function() {
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'ncn', cycle_network: 'US:US', ref: '76'}})).to.eql('US:US 76');
});
it('distinguishes unnamed routes by direction', function() {
expect(iD.utilDisplayName({tags: {network: 'US:US', ref: '66', direction: 'west'}})).to.eql('US:US 66 west');
// Marguerite X: Counter-Clockwise
expect(iD.utilDisplayName({tags: {network: 'Marguerite', ref: 'X', direction: 'anticlockwise'}})).to.eql('Marguerite X anticlockwise');
});
it('distinguishes unnamed routes by waypoints', function() {
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', from: 'Downtown'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', to: 'Kings Island'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', via: 'Montgomery'}})).to.eql('SORTA 3X');
// Green Line: Old Ironsides => Winchester
expect(iD.utilDisplayName({tags: {network: 'VTA', ref: 'Green', from: 'Old Ironsides', to: 'Winchester'}})).to.eql('VTA Green from Old Ironsides to Winchester');
// BART Yellow Line: Antioch => Pittsburg/Bay Point => SFO Airport => Millbrae
expect(iD.utilDisplayName({tags: {network: 'BART', ref: 'Yellow', from: 'Antioch', to: 'Millbrae', via: 'Pittsburg/Bay Point;San Francisco International Airport'}})).to.eql('BART Yellow from Antioch to Millbrae via Pittsburg/Bay Point;San Francisco International Airport');
});
});
});