From 44f3ef8ee11ce9d41d505a12a1b527237487781d Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Sun, 25 Mar 2018 19:25:49 +0200 Subject: [PATCH 01/10] Add fields to Taginfo file (Fixes #4937) --- build_data.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/build_data.js b/build_data.js index 7fe9f6f78..502dbc249 100644 --- a/build_data.js +++ b/build_data.js @@ -67,7 +67,7 @@ module.exports = function buildData() { var presets = generatePresets(tstrings); var defaults = read('data/presets/defaults.json'); var translations = generateTranslations(fields, presets, tstrings); - var taginfo = generateTaginfo(presets); + var taginfo = generateTaginfo(presets, fields); // Additional consistency checks validateCategoryPresets(categories, presets); @@ -300,7 +300,7 @@ function generateTranslations(fields, presets, tstrings) { return translations; } -function generateTaginfo(presets) { +function generateTaginfo(presets, fields) { var taginfo = { 'data_format': 1, 'data_url': 'https://raw.githubusercontent.com/openstreetmap/iD/master/data/taginfo.json', @@ -335,6 +335,25 @@ function generateTaginfo(presets) { taginfo.tags.push(tag); }); + _forEach(fields, function(field) { + var keys = field.keys || [ field.key ] || []; + + keys.forEach(function(key) { + if (field.strings && field.strings.options) { + var values = Object.keys(field.strings.options); + values.forEach(function(value) { + var tag = { key: key, + value: value }; + taginfo.tags.push(tag); + }); + } + else { + tag = { key: key }; + taginfo.tags.push(tag); + } + }); + }); + return taginfo; } From 872fdba3b1140a4a4f51769f6e0113d5e96e395e Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Sun, 25 Mar 2018 19:38:15 +0200 Subject: [PATCH 02/10] fix lint error --- build_data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_data.js b/build_data.js index 502dbc249..93a22cfcc 100644 --- a/build_data.js +++ b/build_data.js @@ -348,7 +348,7 @@ function generateTaginfo(presets, fields) { }); } else { - tag = { key: key }; + var tag = { key: key }; taginfo.tags.push(tag); } }); From 35317d3a95b01b9d6d636a316c4a42bdf54ddaac Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Mon, 26 Mar 2018 21:21:03 +0200 Subject: [PATCH 03/10] Taginfo: Added descriptions, coalesce entries --- build_data.js | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/build_data.js b/build_data.js index 93a22cfcc..cdbb5475a 100644 --- a/build_data.js +++ b/build_data.js @@ -318,6 +318,7 @@ function generateTaginfo(presets, fields) { }; _forEach(presets, function(preset) { + if (preset.suggestion) return; @@ -332,10 +333,14 @@ function generateTaginfo(presets, fields) { tag.value = preset.tags[last]; } - taginfo.tags.push(tag); + if (preset.name) + tag.description = preset.name; + + coalesceTags(taginfo, tag); }); _forEach(fields, function(field) { + var keys = field.keys || [ field.key ] || []; keys.forEach(function(key) { @@ -344,16 +349,53 @@ function generateTaginfo(presets, fields) { values.forEach(function(value) { var tag = { key: key, value: value }; - taginfo.tags.push(tag); + if (field.label) + tag.description = field.label; + coalesceTags(taginfo, tag); }); } else { var tag = { key: key }; - taginfo.tags.push(tag); + if (field.label) + tag.description = field.label; + coalesceTags(taginfo, tag); } }); }); + function coalesceTags(taginfo, tag) { + + if (!tag.key) { + return; + } + + var currentTaginfoEntries = taginfo.tags.filter(function(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; + } + + var isNewDescription = currentTaginfoEntries[0].description.split(' ,') + .indexOf(tag.description) === -1; + + if (isNewDescription) { + currentTaginfoEntries[0].description += ", " + tag.description; + } + } + return taginfo; } From e3536fd05c871555ab70812489fda8261372bf6b Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Mon, 26 Mar 2018 21:29:40 +0200 Subject: [PATCH 04/10] lint fix --- build_data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_data.js b/build_data.js index cdbb5475a..546c937a9 100644 --- a/build_data.js +++ b/build_data.js @@ -388,11 +388,11 @@ function generateTaginfo(presets, fields) { return; } - var isNewDescription = currentTaginfoEntries[0].description.split(' ,') + var isNewDescription = currentTaginfoEntries[0].description.split(', ') .indexOf(tag.description) === -1; if (isNewDescription) { - currentTaginfoEntries[0].description += ", " + tag.description; + currentTaginfoEntries[0].description += ', ' + tag.description; } } From 764acea67fcac7b8df70b59e45440b0ddd75045f Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Tue, 27 Mar 2018 19:41:48 +0200 Subject: [PATCH 05/10] Taginfo Maki icon lookup + Changed description duplicate handling + Removed geometry and icon from translation --- build_data.js | 62 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/build_data.js b/build_data.js index 546c937a9..fa5cf4333 100644 --- a/build_data.js +++ b/build_data.js @@ -14,6 +14,7 @@ const path = require('path'); const shell = require('shelljs'); const YAML = require('js-yaml'); const colors = require('colors/safe'); +const maki = require ('@mapbox/maki'); const fieldSchema = require('./data/presets/schema/field.json'); const presetSchema = require('./data/presets/schema/preset.json'); @@ -159,6 +160,14 @@ function generateFields(tstrings) { } } + if (field.geometry) { + t.geometry = field.geometry; + } + + if (field.icon) { + t.icon = field.icon; + } + fields[id] = field; }); return fields; @@ -297,10 +306,17 @@ function generateTranslations(fields, presets, tstrings) { } }); + // remove fields we're not interested in for translation + _forEach(translations.fields, function(field) { + delete field.icon; + delete field.geometry; + }); + return translations; } function generateTaginfo(presets, fields) { + var taginfo = { 'data_format': 1, 'data_url': 'https://raw.githubusercontent.com/openstreetmap/iD/master/data/taginfo.json', @@ -334,7 +350,15 @@ function generateTaginfo(presets, fields) { } if (preset.name) - tag.description = preset.name; + tag.description = [ preset.name ]; + + if (preset.geometry) { + setObjectType(tag, preset); + } + + if (isMaki(preset.icon)) { + tag.icon_url = 'https://raw.githubusercontent.com/mapbox/maki/master/icons/' + preset.icon + '-11.svg'; + } coalesceTags(taginfo, tag); }); @@ -350,19 +374,24 @@ function generateTaginfo(presets, fields) { var tag = { key: key, value: value }; if (field.label) - tag.description = field.label; + tag.description = [ field.label ]; coalesceTags(taginfo, tag); }); } else { var tag = { key: key }; if (field.label) - tag.description = field.label; + tag.description = [ field.label ]; coalesceTags(taginfo, tag); } }); }); + _forEach(taginfo.tags, function(elem) { + if (elem.description) + elem.description = elem.description.join(', '); + }); + function coalesceTags(taginfo, tag) { if (!tag.key) { @@ -384,18 +413,37 @@ function generateTaginfo(presets, fields) { } if (!currentTaginfoEntries[0].description) { - currentTaginfoEntries[0].description = tag.description; + currentTaginfoEntries[0].description = [ tag.description ]; return; } - var isNewDescription = currentTaginfoEntries[0].description.split(', ') - .indexOf(tag.description) === -1; + var isNewDescription = currentTaginfoEntries[0].description + .indexOf(tag.description) === -1; if (isNewDescription) { - currentTaginfoEntries[0].description += ', ' + tag.description; + currentTaginfoEntries[0].description.push(tag.description[0]); } } + function isMaki(icon) { + var dataFeatureIcons = maki.layouts.all.all; + return (icon && dataFeatureIcons.indexOf(icon) !== -1); + } + + function setObjectType(tag, input) { + tag.object_types = []; + const mapping = { "point" : "node", + "vertex" : "node", + "line" : "way", + "relation" : "relation", + "area" : "area" }; + + input.geometry.forEach(function(geom) { + if (tag.object_types.indexOf(mapping[geom]) === -1) + tag.object_types.push(mapping[geom]); + }); + } + return taginfo; } From c92eb99272d99333e65d1c94f78cdcc217ed5fc8 Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Tue, 27 Mar 2018 20:08:14 +0200 Subject: [PATCH 06/10] Fix GitHub URLs --- build_data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_data.js b/build_data.js index fa5cf4333..67d136699 100644 --- a/build_data.js +++ b/build_data.js @@ -357,7 +357,7 @@ function generateTaginfo(presets, fields) { } if (isMaki(preset.icon)) { - tag.icon_url = 'https://raw.githubusercontent.com/mapbox/maki/master/icons/' + preset.icon + '-11.svg'; + tag.icon_url = 'https://raw.githubusercontent.com/mapbox/maki/master/icons/' + preset.icon + '-15.svg?sanitize=true'; } coalesceTags(taginfo, tag); From 126d33308fa5885923a476e4b01c284e8107555c Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Tue, 27 Mar 2018 20:10:38 +0200 Subject: [PATCH 07/10] Lint fixes --- build_data.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build_data.js b/build_data.js index 67d136699..a649adc79 100644 --- a/build_data.js +++ b/build_data.js @@ -432,11 +432,11 @@ function generateTaginfo(presets, fields) { function setObjectType(tag, input) { tag.object_types = []; - const mapping = { "point" : "node", - "vertex" : "node", - "line" : "way", - "relation" : "relation", - "area" : "area" }; + const mapping = { 'point' : 'node', + 'vertex' : 'node', + 'line' : 'way', + 'relation' : 'relation', + 'area' : 'area' }; input.geometry.forEach(function(geom) { if (tag.object_types.indexOf(mapping[geom]) === -1) From 096585f9a594876785d172e493c44777ff115cf6 Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Tue, 27 Mar 2018 20:42:06 +0200 Subject: [PATCH 08/10] Minor style fixes --- build_data.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/build_data.js b/build_data.js index a649adc79..a4857b31f 100644 --- a/build_data.js +++ b/build_data.js @@ -14,7 +14,7 @@ const path = require('path'); const shell = require('shelljs'); const YAML = require('js-yaml'); const colors = require('colors/safe'); -const maki = require ('@mapbox/maki'); +const maki = require('@mapbox/maki'); const fieldSchema = require('./data/presets/schema/field.json'); const presetSchema = require('./data/presets/schema/preset.json'); @@ -349,8 +349,9 @@ function generateTaginfo(presets, fields) { tag.value = preset.tags[last]; } - if (preset.name) + if (preset.name) { tag.description = [ preset.name ]; + } if (preset.geometry) { setObjectType(tag, preset); @@ -373,15 +374,17 @@ function generateTaginfo(presets, fields) { values.forEach(function(value) { var tag = { key: key, value: value }; - if (field.label) + if (field.label) { tag.description = [ field.label ]; + } coalesceTags(taginfo, tag); }); } else { var tag = { key: key }; - if (field.label) + if (field.label) { tag.description = [ field.label ]; + } coalesceTags(taginfo, tag); } }); @@ -394,9 +397,8 @@ function generateTaginfo(presets, fields) { function coalesceTags(taginfo, tag) { - if (!tag.key) { + if (!tag.key) return; - } var currentTaginfoEntries = taginfo.tags.filter(function(t) { return (t.key === tag.key && @@ -408,9 +410,8 @@ function generateTaginfo(presets, fields) { return; } - if (!tag.description) { + if (!tag.description) return; - } if (!currentTaginfoEntries[0].description) { currentTaginfoEntries[0].description = [ tag.description ]; @@ -439,8 +440,9 @@ function generateTaginfo(presets, fields) { 'area' : 'area' }; input.geometry.forEach(function(geom) { - if (tag.object_types.indexOf(mapping[geom]) === -1) + if (tag.object_types.indexOf(mapping[geom]) === -1) { tag.object_types.push(mapping[geom]); + } }); } From 19de638f58918d7a7cbbfa016f12e45fbf2e44b1 Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Wed, 28 Mar 2018 22:24:17 +0200 Subject: [PATCH 09/10] Bug fix --- build_data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_data.js b/build_data.js index a4857b31f..3e15d0a6a 100644 --- a/build_data.js +++ b/build_data.js @@ -414,12 +414,12 @@ function generateTaginfo(presets, fields) { return; if (!currentTaginfoEntries[0].description) { - currentTaginfoEntries[0].description = [ tag.description ]; + currentTaginfoEntries[0].description = tag.description; return; } var isNewDescription = currentTaginfoEntries[0].description - .indexOf(tag.description) === -1; + .indexOf(tag.description[0]) === -1; if (isNewDescription) { currentTaginfoEntries[0].description.push(tag.description[0]); From 1da6d9029bb9d875dd9702fc629f28b96287b318 Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Wed, 28 Mar 2018 23:12:06 +0200 Subject: [PATCH 10/10] bugfix: don't store icon and geom in t, as no translation is needed here --- build_data.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/build_data.js b/build_data.js index 3e15d0a6a..ec7d64968 100644 --- a/build_data.js +++ b/build_data.js @@ -160,14 +160,6 @@ function generateFields(tstrings) { } } - if (field.geometry) { - t.geometry = field.geometry; - } - - if (field.icon) { - t.icon = field.icon; - } - fields[id] = field; }); return fields; @@ -306,12 +298,6 @@ function generateTranslations(fields, presets, tstrings) { } }); - // remove fields we're not interested in for translation - _forEach(translations.fields, function(field) { - delete field.icon; - delete field.geometry; - }); - return translations; }