Browse Source

Build responses with new source and layer fields

There is no longer any ambiguity in the source field and the layer
(which is stored as _type), so a lot of logic to compute them can simply
read from the elasticsearch document. Hooray!
wof_focus_weighting
Julian Simioni 9 years ago
parent
commit
e98908b3df
  1. 21
      helper/geojsonify.js
  2. 25
      test/unit/helper/geojsonify.js

21
helper/geojsonify.js

@ -25,8 +25,7 @@ var DETAILS_PROPS = [
function lookupSource(src) {
var sources = type_mapping.type_to_source;
return sources.hasOwnProperty(src._type) ? sources[src._type] : src._type;
return src.source;
}
/*
@ -34,24 +33,6 @@ function lookupSource(src) {
* Elasticsearch document source allows a more specific layer name to be chosen
*/
function lookupLayer(src) {
if (src._type === 'geoname') {
if (_.contains(src.category, 'admin')) {
if (_.contains(src.category, 'admin:city')) { return 'locality'; }
if (_.contains(src.category, 'admin:admin1')) { return 'region'; }
if (_.contains(src.category, 'admin:admin2')) { return 'county'; }
return 'neighbourhood'; // this could also be 'local_admin'
}
if (src.name) { return 'venue'; }
if (src.address) { return 'address'; }
}
if (_.contains(type_mapping.types, src._type)) {
return type_mapping.type_to_layer[src._type];
}
logger.warn('[geojsonify]: could not map _type ', src._type);
return src._type;
}

25
test/unit/helper/geojsonify.js

@ -40,7 +40,8 @@ module.exports.tests.search = function(test, common) {
var input = [
{
'_id': 'id1',
'_type': 'type1',
'_type': 'layer1',
'source': 'source1',
'center_point': {
'lat': 51.5337144,
'lon': -0.1069716
@ -72,7 +73,8 @@ module.exports.tests.search = function(test, common) {
},
{
'_id': 'id2',
'_type': 'type2',
'_type': 'layer2',
'source': 'source2',
'name': {
'default': 'Blues Cafe'
},
@ -97,7 +99,8 @@ module.exports.tests.search = function(test, common) {
},
{
'_id': '34633854',
'_type': 'osmway',
'_type': 'way',
'source': 'osm',
'name': {
'default': 'Empire State Building'
},
@ -141,9 +144,9 @@ module.exports.tests.search = function(test, common) {
},
'properties': {
'id': 'id1',
'gid': 'type1:type1:id1',
'layer': 'type1',
'source': 'type1',
'gid': 'source1:layer1:id1',
'layer': 'layer1',
'source': 'source1',
'label': '\'Round Midnight Jazz and Blues Bar, test3, Angel',
'name': '\'Round Midnight Jazz and Blues Bar',
'country_a': 'GBR',
@ -170,9 +173,9 @@ module.exports.tests.search = function(test, common) {
},
'properties': {
'id': 'id2',
'gid': 'type2:type2:id2',
'layer': 'type2',
'source': 'type2',
'gid': 'source2:layer2:id2',
'layer': 'layer2',
'source': 'source2',
'label': 'Blues Cafe, test3, Smithfield',
'name': 'Blues Cafe',
'country_a': 'GBR',
@ -196,8 +199,8 @@ module.exports.tests.search = function(test, common) {
},
'properties': {
'id': '34633854',
'gid': 'osm:venue:34633854',
'layer': 'venue',
'gid': 'osm:way:34633854',
'layer': 'way',
'source': 'osm',
'label': 'Empire State Building, Manhattan, NY',
'name': 'Empire State Building',

Loading…
Cancel
Save