From 4922a37b00c70d040b87f8c25a4da0ad67e901bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Sun, 31 Jul 2016 04:17:06 -0700 Subject: [PATCH 1/3] Combo field with taginfo for road networks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a variation of the combo field for road networks. If the field’s value is blank or shares a prefix with the current country code, search taginfo for values beginning with the country code and a colon. --- data/presets.yaml | 3 +++ data/presets/fields.json | 5 +++++ data/presets/fields/network_road.json | 5 +++++ data/presets/presets.json | 2 +- data/presets/presets/type/route/road.json | 2 +- dist/locales/en.json | 3 +++ modules/ui/fields/combo.js | 21 ++++++++++++++++++--- modules/ui/fields/index.js | 3 ++- 8 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 data/presets/fields/network_road.json diff --git a/data/presets.yaml b/data/presets.yaml index de8e6c720..aea834a00 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -688,6 +688,9 @@ en: rhn: Regional # network_horse field placeholder placeholder: 'Local, Regional, National, International' + network_road: + # network=* + label: Network note: # note=* label: Note diff --git a/data/presets/fields.json b/data/presets/fields.json index 1ae9f33d4..e6bc41498 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -906,6 +906,11 @@ } } }, + "network_road": { + "key": "network", + "type": "networkCombo", + "label": "Network" + }, "network": { "key": "network", "type": "text", diff --git a/data/presets/fields/network_road.json b/data/presets/fields/network_road.json new file mode 100644 index 000000000..abac5b20d --- /dev/null +++ b/data/presets/fields/network_road.json @@ -0,0 +1,5 @@ +{ + "key": "network", + "type": "networkCombo", + "label": "Network" +} \ No newline at end of file diff --git a/data/presets/presets.json b/data/presets/presets.json index 50f82d492..394b62785 100644 --- a/data/presets/presets.json +++ b/data/presets/presets.json @@ -10868,7 +10868,7 @@ "icon": "route-road", "fields": [ "ref", - "network" + "network_road" ] }, "type/route/train": { diff --git a/data/presets/presets/type/route/road.json b/data/presets/presets/type/route/road.json index bfbf4d0c1..d9cd82a4e 100644 --- a/data/presets/presets/type/route/road.json +++ b/data/presets/presets/type/route/road.json @@ -10,6 +10,6 @@ "icon": "route-road", "fields": [ "ref", - "network" + "network_road" ] } \ No newline at end of file diff --git a/dist/locales/en.json b/dist/locales/en.json index d95d3ebbc..270b719d3 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1213,6 +1213,9 @@ "ihn": "International" } }, + "network_road": { + "label": "Network" + }, "network": { "label": "Network" }, diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 281d19814..38b0eb15e 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -3,11 +3,13 @@ import _ from 'lodash'; export { combo as typeCombo, - combo as multiCombo + combo as multiCombo, + combo as networkCombo }; export function combo(field, context) { var dispatch = d3.dispatch('change'), isMulti = (field.type === 'multiCombo'), + isNetwork = (field.type === 'networkCombo'), optstrings = field.strings && field.strings.options, optarray = field.options, snake_case = (field.snake_case || (field.snake_case === undefined)), @@ -16,7 +18,8 @@ export function combo(field, context) { multiData = [], container, input, - entity; + entity, + countryCode; // ensure multiCombo field.key ends with a ':' if (isMulti && field.key.match(/:$/) === null) { @@ -136,11 +139,15 @@ export function combo(field, context) { function setTaginfoValues(q, callback) { var fn = isMulti ? 'multikeys' : 'values'; + var query = (isMulti ? field.key : '') + q; + if (isNetwork && countryCode && countryCode.indexOf(q) === 0) { + query = countryCode + ':'; + } context.taginfo()[fn]({ debounce: true, key: field.key, geometry: context.geometry(entity.id), - query: (isMulti ? field.key : '') + q + query: query }, function(err, data) { if (err) return; comboData = _.map(data, function(d) { @@ -225,6 +232,14 @@ export function combo(field, context) { .attr('id', 'preset-input-' + field.id) .call(initCombo, selection); + if (isNetwork) { + var center = entity.extent(context.graph()).center(); + iD.services.nominatim.init(); + iD.services.nominatim.countryCode(center, function (err, code) { + countryCode = code; + }); + } + input .on('change', change) .on('blur', change); diff --git a/modules/ui/fields/index.js b/modules/ui/fields/index.js index bb38249c2..b7edf10a9 100644 --- a/modules/ui/fields/index.js +++ b/modules/ui/fields/index.js @@ -1,5 +1,5 @@ import { check, defaultcheck} from './check'; -import { combo, multiCombo, typeCombo } from './combo'; +import { combo, multiCombo, networkCombo, typeCombo } from './combo'; import { email, number, tel, text, url } from './input'; import { access } from './access'; @@ -21,6 +21,7 @@ export var fields = { combo: combo, typeCombo: typeCombo, multiCombo: multiCombo, + networkCombo: networkCombo, cycleway: cycleway, text: text, url: url, From 05ecac64cc9d231814b52a0957154e78bfcb0aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Sun, 31 Jul 2016 04:22:43 -0700 Subject: [PATCH 2/3] Compare lowercase value to country code --- modules/ui/fields/combo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 38b0eb15e..2e7b3c4d6 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -140,7 +140,7 @@ export function combo(field, context) { function setTaginfoValues(q, callback) { var fn = isMulti ? 'multikeys' : 'values'; var query = (isMulti ? field.key : '') + q; - if (isNetwork && countryCode && countryCode.indexOf(q) === 0) { + if (isNetwork && countryCode && countryCode.indexOf(q.toLowerCase()) === 0) { query = countryCode + ':'; } context.taginfo()[fn]({ From d1d6b5399ec5733f3cf188bdeba19dfba1b16d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 2 Aug 2016 07:21:32 -0700 Subject: [PATCH 3/3] Filter taginfo by country code prefix taginfo returns results that match anywhere within the string. So in Canada, you might get results like US:CA:SF. This change filters out such results. --- data/presets/fields.json | 2 +- data/presets/fields/cycle_network.json | 2 +- modules/ui/fields/combo.js | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/data/presets/fields.json b/data/presets/fields.json index e6bc41498..e16b320bc 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -367,7 +367,7 @@ }, "cycle_network": { "key": "cycle_network", - "type": "combo", + "type": "networkCombo", "label": "Network" }, "cycleway": { diff --git a/data/presets/fields/cycle_network.json b/data/presets/fields/cycle_network.json index 5565a5dae..3d6974b3d 100644 --- a/data/presets/fields/cycle_network.json +++ b/data/presets/fields/cycle_network.json @@ -1,5 +1,5 @@ { "key": "cycle_network", - "type": "combo", + "type": "networkCombo", "label": "Network" } \ No newline at end of file diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 2e7b3c4d6..fe5bcb903 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -140,7 +140,8 @@ export function combo(field, context) { function setTaginfoValues(q, callback) { var fn = isMulti ? 'multikeys' : 'values'; var query = (isMulti ? field.key : '') + q; - if (isNetwork && countryCode && countryCode.indexOf(q.toLowerCase()) === 0) { + var hasCountryPrefix = isNetwork && countryCode && countryCode.indexOf(q.toLowerCase()) === 0; + if (hasCountryPrefix) { query = countryCode + ':'; } context.taginfo()[fn]({ @@ -150,6 +151,11 @@ export function combo(field, context) { query: query }, function(err, data) { if (err) return; + if (hasCountryPrefix) { + data = _.filter(data, function(d) { + return d.value.toLowerCase().indexOf(countryCode + ':') === 0; + }); + } comboData = _.map(data, function(d) { var k = d.value; if (isMulti) k = k.replace(field.key, '');