Browse Source

Separate real layers and alias layers into separate objects

pull/292/head
Julian Simioni 9 years ago
parent
commit
8b1037d7c8
  1. 2
      helper/query_parser.js
  2. 16
      helper/type_mapping.js
  3. 2
      sanitiser/reverse.js
  4. 2
      sanitiser/search.js
  5. 2
      test/unit/helper/query_parser.js
  6. 8
      test/unit/helper/type_mapping.js
  7. 2
      test/unit/sanitiser/_layers.js

2
helper/query_parser.js

@ -9,7 +9,7 @@ module.exports = {};
module.exports.get_layers = function get_layers(query) {
if (query.length <= 3 ) {
// no address parsing required
return type_mapping.layer_to_type.coarse;
return type_mapping.layer_with_aliases_to_type.coarse;
}
};

16
helper/type_mapping.js

@ -1,3 +1,5 @@
var extend = require('extend');
var ALL_TYPES = [
'geoname',
'osmnode',
@ -55,7 +57,7 @@ var SOURCE_TO_TYPE = {
};
/**
* This includeds alias layers
* This does not included alias layers, those are built separately
*/
var LAYER_TO_TYPE = {
'venue': ['geoname','osmnode','osmway'],
@ -65,14 +67,20 @@ var LAYER_TO_TYPE = {
'county': ['admin2'],
'locality': ['locality'],
'localadmin': ['local_admin'],
'neighbourhood': ['neighborhood'],
'coarse': ['admin0','admin1','admin2','neighborhood','locality','local_admin'],
'neighbourhood': ['neighborhood']
};
var LAYER_ALIASES = {
'coarse': ['admin0','admin1','admin2','neighborhood','locality','local_admin']
};
var LAYER_WITH_ALIASES_TO_TYPE = extend({}, LAYER_ALIASES, LAYER_TO_TYPE);
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
layer_to_type: LAYER_TO_TYPE,
layer_with_aliases_to_type: LAYER_WITH_ALIASES_TO_TYPE
};

2
sanitiser/reverse.js

@ -3,7 +3,7 @@ var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitiser/sanitizeAll'),
sanitizers = {
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_to_type),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_with_aliases_to_type),
sources: require('../sanitiser/_targets')('sources', type_mapping.source_to_type),
size: require('../sanitiser/_size'),
private: require('../sanitiser/_flag_bool')('private', false),

2
sanitiser/search.js

@ -5,7 +5,7 @@ var sanitizeAll = require('../sanitiser/sanitizeAll'),
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
text: require('../sanitiser/_text'),
size: require('../sanitiser/_size'),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_to_type),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_with_aliases_to_type),
sources: require('../sanitiser/_targets')('sources', type_mapping.source_to_type),
private: require('../sanitiser/_flag_bool')('private', false),
geo_search: require('../sanitiser/_geo_search'),

2
test/unit/helper/query_parser.js

@ -1,7 +1,7 @@
var parser = require('../../../helper/query_parser');
var type_mapping = require('../../../helper/type_mapping');
var layers_map = type_mapping.layer_to_type;
var layers_map = type_mapping.layer_with_aliases_to_type;
module.exports.tests = {};

8
test/unit/helper/type_mapping.js

@ -30,7 +30,13 @@ module.exports.tests.interfaces = function(test, common) {
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.equal(Object.keys(type_mapping.layer_to_type).length, 8, 'has correct number of elements');
t.end();
});
test('layer to type mapping (with aliases)', function(t) {
t.ok(check.object(type_mapping.layer_with_aliases_to_type), 'is object');
t.ok(check.hasLength(Object.keys(type_mapping.layer_with_aliases_to_type), 9), 'has correct number of elements');
t.end();
});
};

2
test/unit/sanitiser/_layers.js

@ -1,6 +1,6 @@
var type_mapping = require('../../../helper/type_mapping');
var sanitize = require('../../../sanitiser/_targets')('layers', type_mapping.layer_to_type);
var sanitize = require('../../../sanitiser/_targets')('layers', type_mapping.layer_with_aliases_to_type);
module.exports.tests = {};

Loading…
Cancel
Save