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.
This commit is contained in:
Minh Nguyễn
2016-08-02 07:21:32 -07:00
parent 05ecac64cc
commit d1d6b5399e
3 changed files with 9 additions and 3 deletions

View File

@@ -367,7 +367,7 @@
},
"cycle_network": {
"key": "cycle_network",
"type": "combo",
"type": "networkCombo",
"label": "Network"
},
"cycleway": {

View File

@@ -1,5 +1,5 @@
{
"key": "cycle_network",
"type": "combo",
"type": "networkCombo",
"label": "Network"
}

View File

@@ -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, '');