From 0076200728c5ab8a46e45476deb00160fce9c21e Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Thu, 14 Apr 2016 17:12:44 -0400 Subject: [PATCH] added special case for USA in labels if record is for literal United States, use the full name, otherwise use USA --- helper/labelSchema.js | 13 ++++++++++- test/unit/helper/geojsonify.js | 4 ++-- test/unit/helper/labelGenerator_USA.js | 24 ++++++++++----------- test/unit/helper/labelGenerator_examples.js | 2 +- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/helper/labelSchema.js b/helper/labelSchema.js index 1bce7133..0547e2ad 100644 --- a/helper/labelSchema.js +++ b/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; +} diff --git a/test/unit/helper/geojsonify.js b/test/unit/helper/geojsonify.js index 7297b67d..f8bb9779 100644 --- a/test/unit/helper/geojsonify.js +++ b/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': { diff --git a/test/unit/helper/labelGenerator_USA.js b/test/unit/helper/labelGenerator_USA.js index 5000cac1..bdcc5f2f 100644 --- a/test/unit/helper/labelGenerator_USA.js +++ b/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(); }); diff --git a/test/unit/helper/labelGenerator_examples.js b/test/unit/helper/labelGenerator_examples.js index eed9e506..416b7598 100644 --- a/test/unit/helper/labelGenerator_examples.js +++ b/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(); }); };