Browse Source

added special case for USA in labels

if record is for literal United States, use the full name, otherwise use USA
pull/507/head
Stephen Hess 9 years ago
parent
commit
0076200728
  1. 13
      helper/labelSchema.js
  2. 4
      test/unit/helper/geojsonify.js
  3. 24
      test/unit/helper/labelGenerator_USA.js
  4. 2
      test/unit/helper/labelGenerator_examples.js

13
helper/labelSchema.js

@ -14,7 +14,7 @@ module.exports = {
'borough': getFirstProperty(['borough']),
'local': getFirstProperty(['locality', 'localadmin']),
'regional': getUsOrCaState,
'country': getFirstProperty(['country'])
'country': getUSACountryValue
},
'CAN': {
'local': getFirstProperty(['locality']), // no localadmins in CAN
@ -60,3 +60,14 @@ function getUsOrCaState(record) {
}
}
// this function returns the full name of a country if the result is in the
// country layer (for "United States" record). It returns the abbreviation
// otherwise (eg - Lancaster, PA, USA).
function getUSACountryValue(record) {
if ('country' === record.layer && record.country) {
return record.country;
}
return record.country_a;
}

4
test/unit/helper/geojsonify.js

@ -193,7 +193,7 @@ module.exports.tests.search = function(test, common) {
'gid': 'openstreetmap:venue:node:34633854',
'layer': 'venue',
'source': 'openstreetmap',
'label': 'Empire State Building, Manhattan, New York, NY, United States',
'label': 'Empire State Building, Manhattan, New York, NY, USA',
'name': 'Empire State Building',
'country_a': 'USA',
'country': 'United States',
@ -340,7 +340,7 @@ module.exports.tests.search = function(test, common) {
'localadmin_gid': '404521211',
'locality': 'New York',
'locality_gid': '85977539',
'label': 'East New York, Brooklyn, New York, NY, United States'
'label': 'East New York, Brooklyn, New York, NY, USA'
},
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588],
'geometry': {

24
test/unit/helper/labelGenerator_USA.js

@ -27,7 +27,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'venue name, locality name, region abbr, United States');
t.equal(generator(doc),'venue name, locality name, region abbr, USA');
t.end();
});
@ -47,7 +47,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'venue name, localadmin name, region abbr, United States');
t.equal(generator(doc),'venue name, localadmin name, region abbr, USA');
t.end();
});
@ -68,7 +68,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'house number street name, locality name, region abbr, United States');
t.equal(generator(doc),'house number street name, locality name, region abbr, USA');
t.end();
});
@ -87,7 +87,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'neighbourhood name, locality name, region abbr, United States');
t.equal(generator(doc),'neighbourhood name, locality name, region abbr, USA');
t.end();
});
@ -107,7 +107,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'venue name, borough name, locality name, region abbr, United States');
t.equal(generator(doc),'venue name, borough name, locality name, region abbr, USA');
t.end();
});
@ -125,7 +125,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'locality name, region abbr, United States');
t.equal(generator(doc),'locality name, region abbr, USA');
t.end();
});
@ -142,7 +142,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'localadmin name, region abbr, United States');
t.equal(generator(doc),'localadmin name, region abbr, USA');
t.end();
});
@ -158,7 +158,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'county name, region abbr, United States');
t.equal(generator(doc),'county name, region abbr, USA');
t.end();
});
@ -173,7 +173,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'macrocounty name, region abbr, United States');
t.equal(generator(doc),'macrocounty name, region abbr, USA');
t.end();
});
@ -187,7 +187,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'region name, United States');
t.equal(generator(doc),'region name, USA');
t.end();
});
@ -199,7 +199,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'macroregion name, United States');
t.equal(generator(doc),'macroregion name, USA');
t.end();
});
@ -226,7 +226,7 @@ module.exports.tests.united_states = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'locality name, region name, United States', 'region should be used');
t.equal(generator(doc),'locality name, region name, USA', 'region should be used');
t.end();
});

2
test/unit/helper/labelGenerator_examples.js

@ -39,7 +39,7 @@ module.exports.tests.canada = function(test, common) {
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'1 Main St, Truth or Consequences, NM, United States');
t.equal(generator(doc),'1 Main St, Truth or Consequences, NM, USA');
t.end();
});
};

Loading…
Cancel
Save