* Format a degree coordinate as DMS (degree minute second)for display * @param {number} degrees - degrees to convert to DMS * @param {string} pos - string to use for positive values (either 'north' or 'east') * @param (string) neg - string to use for negative values (either 'south' or
(deg, pos, neg)
| 863 | * @return {string} Text to display |
| 864 | */ |
| 865 | _displayCoordinate(deg, pos, neg) { |
| 866 | const EPSILON = 0.01; |
| 867 | const locale = this._currLocaleCode; |
| 868 | const min = (Math.abs(deg) - Math.floor(Math.abs(deg))) * 60; |
| 869 | let sec = (min - Math.floor(min)) * 60; |
| 870 | |
| 871 | // If you input 45°,90°0'0.5" , sec should be 0.5 instead 0.499999… |
| 872 | // To mitigate precision errors after calculating, round again, see iD#10066 |
| 873 | sec = +sec.toFixed(8); // 0.499999… => 0.5 |
| 874 | |
| 875 | const displayDegrees = this.t('units.arcdegrees', { |
| 876 | quantity: Math.floor(Math.abs(deg)).toLocaleString(locale) |
| 877 | }); |
| 878 | |
| 879 | let displayCoordinate; |
| 880 | |
| 881 | if (Math.abs(sec) > EPSILON) { |
| 882 | displayCoordinate = displayDegrees + |
| 883 | this.t('units.arcminutes', { quantity: Math.floor(min).toLocaleString(locale) }) + |
| 884 | this.t('units.arcseconds', { quantity: Math.round(sec).toLocaleString(locale) }); |
| 885 | } else if (Math.abs(min) > EPSILON) { |
| 886 | displayCoordinate = displayDegrees + |
| 887 | this.t('units.arcminutes', { quantity: Math.round(min).toLocaleString(locale) }); |
| 888 | } else { |
| 889 | displayCoordinate = displayDegrees; |
| 890 | } |
| 891 | |
| 892 | if (deg === 0) { |
| 893 | return displayCoordinate; |
| 894 | } else { |
| 895 | return this.t('units.coordinate', { |
| 896 | coordinate: displayCoordinate, |
| 897 | direction: this.t('units.' + (deg > 0 ? pos : neg)) |
| 898 | }); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | |
| 903 | /** |