Skip to content

Commit 483ea41

Browse files
authored
Merge pull request #8276 from openstreetmap/1ec5-display-name-direction
Label route relations with directions and waypoints
2 parents ddf8682 + 6e30e61 commit 483ea41

File tree

4 files changed

+75
-6
lines changed

4 files changed

+75
-6
lines changed

data/core.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,21 @@ en:
732732
add_fields: "Add field:"
733733
lock:
734734
suggestion: 'The "{label}" field is locked because there is a Wikidata tag. You can delete it or edit the tags in the "Tags" section.'
735+
display_name:
736+
direction: "{direction}"
737+
from_to: "from {from} to {to}"
738+
from_to_via: "from {from} to {to} via {via}"
739+
network_direction: "{network} {direction}"
740+
network_from_to: "{network} from {from} to {to}"
741+
network_from_to_via: "{network} from {from} to {to} via {via}"
742+
ref: "{ref}"
743+
ref_direction: "{ref} {direction}"
744+
ref_from_to: "{ref} from {from} to {to}"
745+
ref_from_to_via: "{ref} from {from} to {to} via {via}"
746+
network_ref: "{network} {ref}"
747+
network_ref_direction: "{network} {ref} {direction}"
748+
network_ref_from_to: "{network} {ref} from {from} to {to}"
749+
network_ref_from_to_via: "{network} {ref} from {from} to {to} via {via}"
735750
background:
736751
title: Background
737752
description: Background Settings

dist/locales/en.min.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

modules/util/util.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,42 @@ export function utilGetAllNodes(ids, graph) {
182182
export function utilDisplayName(entity) {
183183
var localizedNameKey = 'name:' + localizer.languageCode().toLowerCase();
184184
var name = entity.tags[localizedNameKey] || entity.tags.name || '';
185-
var network = entity.tags.cycle_network || entity.tags.network;
185+
if (name) return name;
186+
187+
var tags = {
188+
direction: entity.tags.direction,
189+
from: entity.tags.from,
190+
network: entity.tags.cycle_network || entity.tags.network,
191+
ref: entity.tags.ref,
192+
to: entity.tags.to,
193+
via: entity.tags.via
194+
};
195+
var keyComponents = [];
196+
197+
if (tags.network) {
198+
keyComponents.push('network');
199+
}
200+
if (tags.ref) {
201+
keyComponents.push('ref');
202+
}
186203

187-
if (!name && entity.tags.ref) {
188-
name = entity.tags.ref;
189-
if (network) {
190-
name = network + ' ' + name;
204+
// Routes may need more disambiguation based on direction or destination
205+
if (entity.tags.route) {
206+
if (tags.direction) {
207+
keyComponents.push('direction');
208+
} else if (tags.from && tags.to) {
209+
keyComponents.push('from');
210+
keyComponents.push('to');
211+
if (tags.via) {
212+
keyComponents.push('via');
213+
}
191214
}
192215
}
193216

217+
if (keyComponents.length) {
218+
name = t('inspector.display_name.' + keyComponents.join('_'), tags);
219+
}
220+
194221
return name;
195222
}
196223

test/spec/util/util.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,31 @@ describe('iD.util', function() {
225225
expect(iD.utilUnicodeCharsTruncated('😎😬😆😵😴😄🙂🤔', 255)).to.eql('😎😬😆😵😴😄🙂🤔');
226226
});
227227
});
228+
229+
describe('utilDisplayName', function() {
230+
it('returns the name if tagged with a name', function() {
231+
expect(iD.utilDisplayName({tags: {name: 'East Coast Greenway'}})).to.eql('East Coast Greenway');
232+
});
233+
it('distinguishes unnamed features by ref', function() {
234+
expect(iD.utilDisplayName({tags: {ref: '66'}})).to.eql('66');
235+
});
236+
it('distinguishes unnamed features by network or cycle_network', function() {
237+
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X'}})).to.eql('SORTA 3X');
238+
expect(iD.utilDisplayName({tags: {network: 'ncn', cycle_network: 'US:US', ref: '76'}})).to.eql('US:US 76');
239+
});
240+
it('distinguishes unnamed routes by direction', function() {
241+
expect(iD.utilDisplayName({tags: {network: 'US:US', ref: '66', direction: 'west'}})).to.eql('US:US 66 west');
242+
// Marguerite X: Counter-Clockwise
243+
expect(iD.utilDisplayName({tags: {network: 'Marguerite', ref: 'X', direction: 'anticlockwise'}})).to.eql('Marguerite X anticlockwise');
244+
});
245+
it('distinguishes unnamed routes by waypoints', function() {
246+
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', from: 'Downtown'}})).to.eql('SORTA 3X');
247+
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', to: 'Kings Island'}})).to.eql('SORTA 3X');
248+
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', via: 'Montgomery'}})).to.eql('SORTA 3X');
249+
// Green Line: Old Ironsides => Winchester
250+
expect(iD.utilDisplayName({tags: {network: 'VTA', ref: 'Green', from: 'Old Ironsides', to: 'Winchester'}})).to.eql('VTA Green from Old Ironsides to Winchester');
251+
// BART Yellow Line: Antioch => Pittsburg/Bay Point => SFO Airport => Millbrae
252+
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');
253+
});
254+
});
228255
});

0 commit comments

Comments
 (0)