Browse Source

Derive type, source, and layer list instead of hardcoding

pull/292/head
Julian Simioni 9 years ago
parent
commit
d4fff26574
  1. 2
      helper/geojsonify.js
  2. 25
      helper/type_mapping.js
  3. 2
      helper/types.js
  4. 6
      test/unit/helper/type_mapping.js

2
helper/geojsonify.js

@ -46,7 +46,7 @@ function lookupLayer(src) {
if (src.address) { return 'address'; } 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]; return type_mapping.type_to_layer[src._type];
} }

25
helper/type_mapping.js

@ -1,19 +1,5 @@
var extend = require('extend'); var extend = require('extend');
var ALL_TYPES = [
'geoname',
'osmnode',
'osmway',
'admin0',
'admin1',
'admin2',
'neighborhood',
'locality',
'local_admin',
'osmaddress',
'openaddresses'
];
var TYPE_TO_SOURCE = { var TYPE_TO_SOURCE = {
'geoname': 'gn', 'geoname': 'gn',
'osmnode': 'osm', 'osmnode': 'osm',
@ -76,6 +62,13 @@ var LAYER_ALIASES = {
var LAYER_WITH_ALIASES_TO_TYPE = extend({}, LAYER_ALIASES, LAYER_TO_TYPE); 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 * Calculate the set-style intersection of two arrays
*/ */
@ -90,7 +83,9 @@ var sourceAndLayerToType = function sourceAndLayerToType(source, layer) {
}; };
module.exports = { module.exports = {
types_list: ALL_TYPES, types: TYPES,
sources: SOURCES,
layers: LAYERS,
type_to_source: TYPE_TO_SOURCE, type_to_source: TYPE_TO_SOURCE,
type_to_layer: TYPE_TO_LAYER, type_to_layer: TYPE_TO_LAYER,
source_to_type: SOURCE_TO_TYPE, source_to_type: SOURCE_TO_TYPE,

2
helper/types.js

@ -24,7 +24,7 @@ module.exports = function calculate_types(clean_types) {
* perform a set intersection of their specified types * perform a set intersection of their specified types
*/ */
if (clean_types.from_layers || clean_types.from_sources) { 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) { if (clean_types.from_layers) {
types = intersection(types, clean_types.from_layers); types = intersection(types, clean_types.from_layers);

6
test/unit/helper/type_mapping.js

@ -4,9 +4,9 @@ var type_mapping = require('../../../helper/type_mapping');
module.exports.tests = {}; module.exports.tests = {};
module.exports.tests.interfaces = function(test, common) { module.exports.tests.interfaces = function(test, common) {
test('types_list', function(t) { test('types list', function(t) {
t.ok(check.array(type_mapping.types_list), 'is array'); t.ok(check.array(type_mapping.types), 'is array');
t.ok(check.hasLength(type_mapping.types_list, 11), 'has correct number of elements'); t.ok(check.hasLength(type_mapping.types, 11), 'has correct number of elements');
t.end(); t.end();
}); });

Loading…
Cancel
Save