* displayName * Get a localized display name for a map feature * @param {Object} tags * @param {boolean} hideNetwork - If true, the `network` tag will not be used in the name to prevent * it being shown twice (see PR iD#8707#discussion_r712658175) * @return {string} A name strin
(tags, hideNetwork)
| 573 | * @return {string} A name string suitable for display |
| 574 | */ |
| 575 | displayName(tags, hideNetwork) { |
| 576 | const code = this._currLanguageCode.toLowerCase(); |
| 577 | |
| 578 | const route = tags.route; |
| 579 | const name = tags[`name:${code}`] ?? tags.name ?? ''; |
| 580 | |
| 581 | // Gather the properties we may use to construct a display name |
| 582 | const props = { |
| 583 | name: name, |
| 584 | direction: tags.direction, |
| 585 | from: tags.from, |
| 586 | network: hideNetwork ? undefined : (tags.cycle_network ?? tags.network), |
| 587 | ref: tags.ref, |
| 588 | to: tags.to, |
| 589 | via: tags.via |
| 590 | }; |
| 591 | |
| 592 | // For routes, prefer `network+ref+name` or `ref+name` over `name` |
| 593 | if (route && props.ref && props.name) { |
| 594 | return props.network ? |
| 595 | this.t('inspector.display_name.network_ref_name', props) : |
| 596 | this.t('inspector.display_name.ref_name', props); |
| 597 | } |
| 598 | |
| 599 | // If we have a name, return it |
| 600 | if (name) { |
| 601 | return name; |
| 602 | } |
| 603 | |
| 604 | // Construct a name from other tags. |
| 605 | let keyComponents = []; |
| 606 | if (props.network) { |
| 607 | keyComponents.push('network'); |
| 608 | } |
| 609 | if (props.ref) { |
| 610 | keyComponents.push('ref'); |
| 611 | } |
| 612 | |
| 613 | // Routes may need more disambiguation based on direction or destination |
| 614 | if (route) { |
| 615 | if (props.direction) { |
| 616 | keyComponents.push('direction'); |
| 617 | } else if (props.from && props.to) { |
| 618 | keyComponents.push('from'); |
| 619 | keyComponents.push('to'); |
| 620 | if (props.via) { |
| 621 | keyComponents.push('via'); |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | if (keyComponents.length) { |
| 627 | return this.t('inspector.display_name.' + keyComponents.join('_'), props); |
| 628 | } |
| 629 | |
| 630 | // bhousel 3/28/22 - no labels for addresses for now |
| 631 | // // if there's still no name found, try addr:housename |
| 632 | // if (tags['addr:housename']) { |
no test coverage detected