in build_data.js [472:632]
function generateTaginfo(presets, fields) {
let taginfo = {
'data_format': 1,
'data_url': 'https://raw.githubusercontent.com/openstreetmap/iD/master/data/taginfo.json',
'project': {
'name': 'iD Editor',
'description': 'Online editor for OSM data.',
'project_url': 'https://github.com/openstreetmap/iD',
'doc_url': 'https://github.com/openstreetmap/iD/blob/master/data/presets/README.md',
'icon_url': 'https://cdn.jsdelivr.net/gh/openstreetmap/iD@release/dist/img/logo.png',
'keywords': ['editor']
},
'tags': []
};
Object.keys(presets).forEach(id => {
let preset = presets[id];
if (preset.suggestion) return;
let keys = Object.keys(preset.tags);
let last = keys[keys.length - 1];
let tag = { key: last };
if (!last) return;
if (preset.tags[last] !== '*') {
tag.value = preset.tags[last];
}
if (preset.name) {
let legacy = (preset.searchable === false) ? ' (unsearchable)' : '';
tag.description = [ '🄿 ' + preset.name + legacy ];
}
if (preset.geometry) {
setObjectType(tag, preset);
}
// add icon
if (/^maki-/.test(preset.icon)) {
tag.icon_url = 'https://cdn.jsdelivr.net/gh/mapbox/maki/icons/' +
preset.icon.replace(/^maki-/, '') + '-15.svg';
} else if (/^temaki-/.test(preset.icon)) {
tag.icon_url = 'https://cdn.jsdelivr.net/gh/bhousel/temaki/icons/' +
preset.icon.replace(/^temaki-/, '') + '.svg';
} else if (/^fa[srb]-/.test(preset.icon)) {
tag.icon_url = 'https://cdn.jsdelivr.net/gh/openstreetmap/iD@master/svg/fontawesome/' +
preset.icon + '.svg';
} else if (/^iD-/.test(preset.icon)) {
tag.icon_url = 'https://cdn.jsdelivr.net/gh/openstreetmap/iD@master/svg/iD-sprite/presets/' +
preset.icon.replace(/^iD-/, '') + '.svg';
} else if (/^tnp-/.test(preset.icon)) {
tag.icon_url = 'https://cdn.jsdelivr.net/gh/openstreetmap/iD@master/svg/the-noun-project/' +
preset.icon.replace(/^tnp-/, '') + '.svg';
}
coalesceTags(taginfo, tag);
});
Object.keys(fields).forEach(id => {
const field = fields[id];
const keys = field.keys || [ field.key ] || [];
const isRadio = (field.type === 'radio' || field.type === 'structureRadio');
keys.forEach(key => {
if (field.strings && field.strings.options && !isRadio) {
let values = Object.keys(field.strings.options);
values.forEach(value => {
if (value === 'undefined' || value === '*' || value === '') return;
let tag = { key: key, value: value };
if (field.label) {
tag.description = [ '🄵 ' + field.label ];
}
coalesceTags(taginfo, tag);
});
} else {
let tag = { key: key };
if (field.label) {
tag.description = [ '🄵 ' + field.label ];
}
coalesceTags(taginfo, tag);
}
});
});
deprecated.forEach(elem => {
let old = elem.old;
let oldKeys = Object.keys(old);
if (oldKeys.length === 1) {
let oldKey = oldKeys[0];
let tag = { key: oldKey };
let oldValue = old[oldKey];
if (oldValue !== '*') tag.value = oldValue;
let replacementStrings = [];
for (let replaceKey in elem.replace) {
let replaceValue = elem.replace[replaceKey];
if (replaceValue === '$1') replaceValue = '*';
replacementStrings.push(replaceKey + '=' + replaceValue);
}
let description = '🄳';
if (replacementStrings.length > 0) {
description += ' ➜ ' + replacementStrings.join(' + ');
}
tag.description = [description];
coalesceTags(taginfo, tag);
}
});
taginfo.tags.forEach(elem => {
if (elem.description) {
elem.description = elem.description.join(', ');
}
});
function coalesceTags(taginfo, tag) {
if (!tag.key) return;
let currentTaginfoEntries = taginfo.tags.filter(t => {
return (t.key === tag.key && t.value === tag.value);
});
if (currentTaginfoEntries.length === 0) {
taginfo.tags.push(tag);
return;
}
if (!tag.description) return;
if (!currentTaginfoEntries[0].description) {
currentTaginfoEntries[0].description = tag.description;
return;
}
let isNewDescription = currentTaginfoEntries[0].description
.indexOf(tag.description[0]) === -1;
if (isNewDescription) {
currentTaginfoEntries[0].description.push(tag.description[0]);
}
}
function setObjectType(tag, input) {
tag.object_types = [];
const mapping = {
'point' : 'node',
'vertex' : 'node',
'line' : 'way',
'relation' : 'relation',
'area' : 'area'
};
input.geometry.forEach(geom => {
if (tag.object_types.indexOf(mapping[geom]) === -1) {
tag.object_types.push(mapping[geom]);
}
});
}
return taginfo;
}