Skip to content

Commit

Permalink
Avoid combining PTv2-formatted name with ref
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Sep 24, 2024
1 parent bc23b4f commit e553f1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,14 @@ export function utilDisplayName(entity, hideNetwork) {

// for routes, prefer `network+ref+name` or `ref+name` over `name`
if (name && tags.ref && entity.tags.route) {
return tags.network
? t('inspector.display_name.network_ref_name', tags)
: t('inspector.display_name.ref_name', tags);
// 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;

Expand Down
5 changes: 5 additions & 0 deletions test/spec/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ describe('iD.util', function() {
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');
Expand Down

0 comments on commit e553f1e

Please sign in to comment.