mirror of https://github.com/pelias/api.git
Julian Simioni
9 years ago
3 changed files with 125 additions and 0 deletions
@ -0,0 +1,78 @@
|
||||
var ALL_TYPES = [ |
||||
'geoname', |
||||
'osmnode', |
||||
'osmway', |
||||
'admin0', |
||||
'admin1', |
||||
'admin2', |
||||
'neighborhood', |
||||
'locality', |
||||
'local_admin', |
||||
'osmaddress', |
||||
'openaddresses' |
||||
]; |
||||
|
||||
var TYPE_TO_SOURCE = { |
||||
'geoname': 'gn', |
||||
'osmnode': 'osm', |
||||
'osmway': 'osm', |
||||
'admin0': 'qs', |
||||
'admin1': 'qs', |
||||
'admin2': 'qs', |
||||
'neighborhood': 'qs', |
||||
'locality': 'qs', |
||||
'local_admin': 'qs', |
||||
'osmaddress': 'osm', |
||||
'openaddresses': 'oa' |
||||
}; |
||||
|
||||
/* |
||||
* This doesn't include alias layers such as coarse |
||||
*/ |
||||
var TYPE_TO_LAYER = { |
||||
'geoname': 'venue', |
||||
'osmnode': 'venue', |
||||
'osmway': 'venue', |
||||
'admin0': 'country', |
||||
'admin1': 'region', |
||||
'admin2': 'county', |
||||
'neighborhood': 'neighbourhood', |
||||
'locality': 'locality', |
||||
'local_admin': 'localadmin', |
||||
'osmaddress': 'address', |
||||
'openaddresses': 'address' |
||||
}; |
||||
|
||||
var SOURCE_TO_TYPE = { |
||||
'gn' : ['geoname'], |
||||
'geonames' : ['geoname'], |
||||
'oa' : ['openaddresses'], |
||||
'openaddresses' : ['openaddresses'], |
||||
'qs' : ['admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin'], |
||||
'quattroshapes' : ['admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin'], |
||||
'osm' : ['osmaddress', 'osmnode', 'osmway'], |
||||
'openstreetmap' : ['osmaddress', 'osmnode', 'osmway'] |
||||
}; |
||||
|
||||
/** |
||||
* This includeds alias layers |
||||
*/ |
||||
var LAYER_TO_TYPE = { |
||||
'venue': ['geoname','osmnode','osmway'], |
||||
'address': ['osmaddress','openaddresses'], |
||||
'country': ['admin0'], |
||||
'region': ['admin1'], |
||||
'county': ['admin2'], |
||||
'locality': ['locality'], |
||||
'localadmin': ['local_admin'], |
||||
'neighbourhood': ['neighborhood'], |
||||
'coarse': ['admin0','admin1','admin2','neighborhood','locality','local_admin'], |
||||
}; |
||||
|
||||
module.exports = { |
||||
types_list: ALL_TYPES, |
||||
type_to_source: TYPE_TO_SOURCE, |
||||
type_to_layer: TYPE_TO_LAYER, |
||||
source_to_type: SOURCE_TO_TYPE, |
||||
layer_to_type: LAYER_TO_TYPE |
||||
}; |
@ -0,0 +1,46 @@
|
||||
var check = require('check-types'); |
||||
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'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('type to source mapping', function(t) { |
||||
t.ok(check.object(type_mapping.type_to_source), 'is object'); |
||||
t.ok(check.hasLength(Object.keys(type_mapping.type_to_source), 11), 'has correct number of elements'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('type to layer mapping', function(t) { |
||||
t.ok(check.object(type_mapping.type_to_layer), 'is object'); |
||||
t.ok(check.hasLength(Object.keys(type_mapping.type_to_layer), 11), 'has correct number of elements'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('source to type mapping', function(t) { |
||||
t.ok(check.object(type_mapping.source_to_type), 'is object'); |
||||
t.ok(check.hasLength(Object.keys(type_mapping.source_to_type), 8), 'has correct number of elements'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('layer to type mapping', function(t) { |
||||
t.ok(check.object(type_mapping.layer_to_type), 'is object'); |
||||
t.ok(check.hasLength(Object.keys(type_mapping.layer_to_type), 9), 'has correct number of elements'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.all = function (tape, common) { |
||||
function test(name, testFunction) { |
||||
return tape('type_mapping: ' + name, testFunction); |
||||
} |
||||
|
||||
for( var testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
Loading…
Reference in new issue