Merge pull request #3302 from 1ec5/network-combo

Combo field with taginfo for road networks
This commit is contained in:
Bryan Housel
2016-08-02 15:41:55 -04:00
committed by GitHub
9 changed files with 46 additions and 8 deletions
+3
View File
@@ -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
+6 -1
View File
@@ -367,7 +367,7 @@
},
"cycle_network": {
"key": "cycle_network",
"type": "combo",
"type": "networkCombo",
"label": "Network"
},
"cycleway": {
@@ -906,6 +906,11 @@
}
}
},
"network_road": {
"key": "network",
"type": "networkCombo",
"label": "Network"
},
"network": {
"key": "network",
"type": "text",
+1 -1
View File
@@ -1,5 +1,5 @@
{
"key": "cycle_network",
"type": "combo",
"type": "networkCombo",
"label": "Network"
}
+5
View File
@@ -0,0 +1,5 @@
{
"key": "network",
"type": "networkCombo",
"label": "Network"
}
+1 -1
View File
@@ -10868,7 +10868,7 @@
"icon": "route-road",
"fields": [
"ref",
"network"
"network_road"
]
},
"type/route/train": {
+1 -1
View File
@@ -10,6 +10,6 @@
"icon": "route-road",
"fields": [
"ref",
"network"
"network_road"
]
}
+3
View File
@@ -1213,6 +1213,9 @@
"ihn": "International"
}
},
"network_road": {
"label": "Network"
},
"network": {
"label": "Network"
},
+24 -3
View File
@@ -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,13 +139,23 @@ export function combo(field, context) {
function setTaginfoValues(q, callback) {
var fn = isMulti ? 'multikeys' : 'values';
var query = (isMulti ? field.key : '') + q;
var hasCountryPrefix = isNetwork && countryCode && countryCode.indexOf(q.toLowerCase()) === 0;
if (hasCountryPrefix) {
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;
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, '');
@@ -225,6 +238,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);
+2 -1
View File
@@ -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,