diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 9822ad02..94b41b84 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -46,7 +46,7 @@ function lookupLayer(src) { if (src.address) { return 'address'; } } - if (_.contains(type_mapping.types_list, src._type)) { + if (_.contains(type_mapping.types, src._type)) { return type_mapping.type_to_layer[src._type]; } diff --git a/helper/type_mapping.js b/helper/type_mapping.js index a00979b7..ab7bbe56 100644 --- a/helper/type_mapping.js +++ b/helper/type_mapping.js @@ -1,19 +1,5 @@ var extend = require('extend'); -var ALL_TYPES = [ - 'geoname', - 'osmnode', - 'osmway', - 'admin0', - 'admin1', - 'admin2', - 'neighborhood', - 'locality', - 'local_admin', - 'osmaddress', - 'openaddresses' -]; - var TYPE_TO_SOURCE = { 'geoname': 'gn', 'osmnode': 'osm', @@ -76,6 +62,13 @@ var LAYER_ALIASES = { var LAYER_WITH_ALIASES_TO_TYPE = extend({}, LAYER_ALIASES, LAYER_TO_TYPE); +/* + * derive the list of types, sources, and layers from above mappings + */ +var TYPES = Object.keys(TYPE_TO_SOURCE); +var SOURCES = Object.keys(SOURCE_TO_TYPE); +var LAYERS = Object.keys(LAYER_TO_TYPE); + /** * Calculate the set-style intersection of two arrays */ @@ -90,7 +83,9 @@ var sourceAndLayerToType = function sourceAndLayerToType(source, layer) { }; module.exports = { - types_list: ALL_TYPES, + types: TYPES, + sources: SOURCES, + layers: LAYERS, type_to_source: TYPE_TO_SOURCE, type_to_layer: TYPE_TO_LAYER, source_to_type: SOURCE_TO_TYPE, diff --git a/helper/types.js b/helper/types.js index c057345f..aa3337e8 100644 --- a/helper/types.js +++ b/helper/types.js @@ -24,7 +24,7 @@ module.exports = function calculate_types(clean_types) { * perform a set intersection of their specified types */ if (clean_types.from_layers || clean_types.from_sources) { - var types = type_mapping.types_list; + var types = type_mapping.types; if (clean_types.from_layers) { types = intersection(types, clean_types.from_layers); diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index fa50c191..144fadfb 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -4,9 +4,9 @@ var type_mapping = require('../../../helper/type_mapping'); module.exports.tests = {}; module.exports.tests.interfaces = function(test, common) { - test('types_list', function(t) { - t.ok(check.array(type_mapping.types_list), 'is array'); - t.ok(check.hasLength(type_mapping.types_list, 11), 'has correct number of elements'); + test('types list', function(t) { + t.ok(check.array(type_mapping.types), 'is array'); + t.ok(check.hasLength(type_mapping.types, 11), 'has correct number of elements'); t.end(); });