diff --git a/proxy/js/features.mjs b/proxy/js/features.mjs index 197ca88d..eda138c3 100644 --- a/proxy/js/features.mjs +++ b/proxy/js/features.mjs @@ -141,19 +141,29 @@ const railwayLineFeatures = { electrification_state: { name: 'Electrification', }, - // TODO format with 2 digits and Hz frequency: { name: 'Frequency', + format: { + template: '%.2d Hz', + }, }, - // TODO format with V voltage: { name: 'Voltage', + format: { + template: '%d V', + }, }, future_frequency: { name: 'Future frequency', + format: { + template: '%.2d Hz', + }, }, future_voltage: { name: 'Future voltage', + format: { + template: '%d V', + }, }, gauge_label: { name: 'Gauge', diff --git a/proxy/js/ui.js b/proxy/js/ui.js index cc91ed34..3e272020 100644 --- a/proxy/js/ui.js +++ b/proxy/js/ui.js @@ -703,8 +703,18 @@ function popupContent(feature) { const featureType = featureContent && featureContent.type || 'point'; const osmType = featureType === 'point' ? 'node' : 'way'; + const formatPropertyValue = (value, format) => { + if (!format) { + return String(value); + } else if (format.template) { + return format.template.replace('%s', () => String(value)).replace(/%(\.(\d+))?d/, (_1, _2, decimals) => value.toFixed(Number(decimals))); + } else { + return String(value); + } + } + const propertyValues = Object.entries(featureCatalog.properties || {}) - .map(([property, {name}]) => properties[property] ? `${name}${properties[property] === true ? '' : `: ${properties[property]}`}` : '') + .map(([property, {name, format}]) => (properties[property] !== undefined && properties[property] !== null && properties[property] !== '' && properties[property] !== false) ? `${name}${properties[property] === true ? '' : `: ${formatPropertyValue(properties[property], format)}`}` : '') .filter(it => it) .join('')