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

Include route number in label of named route relations #10478

Open
wants to merge 2 commits into
base: develop
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
2 changes: 2 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ en:
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:
network_ref_name: "{network} {ref}: {name}"
ref_name: "{ref}: {name}"
Comment on lines +766 to +767
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I sometimes encounter situations where it would be nice to also append from=*, to=*, and via=* for disambiguation – just like when the route has a ref=* instead of a name=*. Of course, the name might push all these extra details off out of view, but at least they’d appear in a tooltip as a last resort.

direction: "{direction}"
network: "{network}"
from_to: "from {from} to {to}"
Expand Down
6 changes: 5 additions & 1 deletion modules/ui/sections/raw_membership_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ export function uiSectionRawMembershipEditor(context) {
.attr('class', 'member-entity-name')
.classed('has-colour', d => d.relation.tags.colour && isColourValid(d.relation.tags.colour))
.style('border-color', d => d.relation.tags.colour)
.text(function(d) { return utilDisplayName(d.relation); });
.html(function(d) {
const matched = presetManager.match(d.relation, context.graph());
// hide the network from the name if there is NSI match
return utilDisplayName(d.relation, matched.suggestion);
});

labelEnter
.append('button')
Expand Down
25 changes: 21 additions & 4 deletions modules/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,37 @@ export function utilGetAllNodes(ids, graph) {
}
}


export function utilDisplayName(entity) {
/**
* @param {boolean} hideNetwork If true, the `network` tag will not be used in the name to prevent
* it being shown twice (see PR #8707#discussion_r712658175)
*/
export function utilDisplayName(entity, hideNetwork) {
var localizedNameKey = 'name:' + localizer.languageCode().toLowerCase();
var name = entity.tags[localizedNameKey] || entity.tags.name || '';
if (name) return name;

var tags = {
name,
direction: entity.tags.direction,
from: entity.tags.from,
network: entity.tags.cycle_network || entity.tags.network,
network: hideNetwork ? undefined : (entity.tags.cycle_network || entity.tags.network),
ref: entity.tags.ref,
to: entity.tags.to,
via: entity.tags.via
};

// for routes, prefer `network+ref+name` or `ref+name` over `name`
if (name && tags.ref && entity.tags.route) {
// A right arrow likely indicates a formulaic “name” as specified by the Public Transport v2 schema.
// This name format already contains enough details to disambiguate the feature; avoid duplicating these details.
var nameIsPTv2 = name.match(/→|[-=]>/);
if (!nameIsPTv2) {
return tags.network
? t('inspector.display_name.network_ref_name', tags)
: t('inspector.display_name.ref_name', tags);
}
}
if (name) return name;

var keyComponents = [];

if (tags.network) {
Expand Down
19 changes: 19 additions & 0 deletions test/spec/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,25 @@ describe('iD.util', 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('returns just the name for non-routes', function() {
expect(iD.utilDisplayName({tags: { name: 'Abyssinian Room', ref: '260-115' }})).to.eql('Abyssinian Room');
});
it('returns just the name for route with PTv2-formatted names', function() {
expect(iD.utilDisplayName({tags: { name: 'NORTA 2: French Market → Canal at Bourbon', network: 'NORTA', ref: '2', from: 'French Market', to: 'Canal at Bourbon'}})).to.eql('NORTA 2: French Market → Canal at Bourbon');
expect(iD.utilDisplayName({tags: { name: 'VTA 64A: McKee & White => San Jose Diridon => Ohlone/Chynoweth', network: 'VTA', ref: '64A', from: 'McKee & White', to: 'Ohlone/Chynoweth', via: 'San Jose Diridon'}})).to.eql('VTA 64A: McKee & White => San Jose Diridon => Ohlone/Chynoweth');
expect(iD.utilDisplayName({tags: { name: 'Bus 224: Downtown Garland Station -> Lake Ray Hubbard TC -> Downtown Dallas', route: 'bus', ref: '224', from: 'Downtown Garland Station', to: 'Downtown Dallas', via: 'Lake Ray Hubbard TC'}})).to.eql('Bus 224: Downtown Garland Station -> Lake Ray Hubbard TC -> Downtown Dallas');
});
it('returns the name and the ref for routes', function() {
expect(iD.utilDisplayName({tags: { name: 'Lynfield Express', ref: '25L', route: 'bus' }})).to.eql('25L: Lynfield Express');
expect(iD.utilDisplayName({tags: { name: 'Kāpiti Expressway', ref: 'SH1', route: 'road' }})).to.eql('SH1: Kāpiti Expressway');
});
it('returns the name, ref, and network for routes', function() {
expect(iD.utilDisplayName({tags: { name: 'Lynfield Express', ref: '25L', network: 'AT', route: 'bus' }})).to.eql('AT 25L: Lynfield Express');
});
it('does not use the network tag if the hideNetwork argument is true', function() {
expect(iD.utilDisplayName({tags: { name: 'Lynfield Express', ref: '25L', network: 'AT', route: 'bus' }}, true)).to.eql('25L: Lynfield Express');
expect(iD.utilDisplayName({tags: { network: 'SORTA', ref: '3X' }}, true)).to.eql('3X');
});
it('distinguishes unnamed features by ref', function() {
expect(iD.utilDisplayName({tags: {ref: '66'}})).to.eql('66');
});
Expand Down
Loading