Browse Source

Merge branch 'master' of github.com:pelias/api into confidence

pull/219/head
Diana Shkolnikov 9 years ago
parent
commit
771c5563ec
  1. 81
      helper/geojsonify.js
  2. 2
      test/ciao/index.coffee
  3. 2
      test/ciao/place/msuccess.coffee
  4. 2
      test/ciao/place/success.coffee
  5. 4
      test/ciao/reverse/success.coffee
  6. 4
      test/ciao/search/success.coffee
  7. 4
      test/ciao/suggest/nearby_nobias.coffee
  8. 4
      test/ciao/suggest/success.coffee
  9. 4
      test/ciao/suggest/success_nearby.coffee

81
helper/geojsonify.js

@ -1,7 +1,9 @@
var GeoJSON = require('geojson'),
extent = require('geojson-extent'),
outputGenerator = require('./outputGenerator');
var GeoJSON = require('geojson');
var extent = require('geojson-extent');
var outputGenerator = require('./outputGenerator');
var logger = require('pelias-logger').get('api');
// Properties to be copied when details=true
var DETAILS_PROPS = [
@ -20,20 +22,62 @@ var DETAILS_PROPS = [
'confidence'
];
var META_MAP = {
'geoname': { type: '???', source: 'gn' }, // TODO: not sure how to map. will need to use categories?
'osmnode': { type: 'venue', source: 'osm' },
'osmway': { type: 'venue', source: 'osm' },
'admin0': { type: 'country', source: 'qs' },
'admin1': { type: 'region', source: 'qs' },
'admin2': { type: 'county', source: 'qs' },
'neighborhood': { type: 'neighbourhood', source: 'qs' },
'locality': { type: 'locality', source: 'qs' },
'local_admin': { type: 'local_admin', source: 'qs' },
'osmaddress': { type: 'address', source: 'osm' },
'openaddresses': { type: 'address', source: 'oa' }
var SOURCES = {
'geoname': 'gn',
'osmnode': 'osm',
'osmway': 'osm',
'admin0': 'qs',
'admin1': 'qs',
'admin2': 'qs',
'neighborhood': 'qs',
'locality': 'qs',
'local_admin': 'qs',
'osmaddress': 'osm',
'openaddresses': 'oa'
};
function lookupSource(src) {
return SOURCES.hasOwnProperty(src._type) ? SOURCES[src._type] : src._type;
}
function lookupLayer(src) {
switch(src._type) {
case 'osmnode':
case 'osmway':
return 'venue';
case 'admin0':
return 'country';
case 'admin1':
return 'region';
case 'admin2':
return 'county';
case 'neighborhood':
return 'neighbourhood';
case 'locality':
return 'locality';
case 'local_admin':
return 'localadmin';
case 'osmaddress':
case 'openaddresses':
return 'address';
case 'geoname':
if (src.category && src.category.indexOf('admin') !== -1) {
if (src.category.indexOf('admin:city') !== -1) { return 'locality'; }
if (src.category.indexOf('admin:admin1') !== -1) { return 'region'; }
if (src.category.indexOf('admin:admin2') !== -1) { return 'county'; }
return 'neighbourhood'; // this could also be 'local_admin'
}
if (src.name) { return 'venue'; }
if (src.address) { return 'address'; }
}
logger.warn('[geojsonify]: could not map _type ', src._type);
return src._type;
}
function geojsonifyPlaces( docs, params ){
var details = params ? params.details : {};
@ -149,12 +193,9 @@ function copyProperties( source, props, dst ) {
* @param {object} dst
*/
function addMetaData(src, dst) {
// lookup mapping, or set both values to _type if not found
var meta = META_MAP[src._type] || { type: src._type, source: src._type };
dst.id = src._id;
dst.layer = meta.type;
dst.source = meta.source;
dst.layer = lookupLayer(src);
dst.source = lookupSource(src);
}
/**

2
test/ciao/index.coffee

@ -1,6 +1,6 @@
#> api root
path: '/'
path: '/v1/'
#? endpoint available
response.statusCode.should.equal 200

2
test/ciao/place/msuccess.coffee

@ -1,6 +1,6 @@
#> valid place query
path: '/place?id=geoname:4221195&id=geoname:4193595'
path: '/v1/place?id=geoname:4221195&id=geoname:4193595'
#? 200 ok
response.statusCode.should.equal 200

2
test/ciao/place/success.coffee

@ -1,6 +1,6 @@
#> valid place query
path: '/place?id=geoname:4221195'
path: '/v1/place?id=geoname:4221195'
#? 200 ok
response.statusCode.should.equal 200

4
test/ciao/reverse/success.coffee

@ -1,5 +1,5 @@
#> valid reverse query
path: '/reverse?lat=29.49136&lon=-82.50622'
path: '/v1/reverse?lat=29.49136&lon=-82.50622'
#? 200 ok
response.statusCode.should.equal 200
@ -12,4 +12,4 @@ json.date.should.be.within now-5000, now+5000
#? valid geojson
json.type.should.equal 'FeatureCollection'
json.features.should.be.instanceof Array
json.features.should.be.instanceof Array

4
test/ciao/search/success.coffee

@ -1,5 +1,5 @@
#> valid search query
path: '/search?input=lake&lat=29.49136&lon=-82.50622'
path: '/v1/search?input=lake&lat=29.49136&lon=-82.50622'
#? 200 ok
response.statusCode.should.equal 200
@ -12,4 +12,4 @@ json.date.should.be.within now-5000, now+5000
#? valid geojson
json.type.should.equal 'FeatureCollection'
json.features.should.be.instanceof Array
json.features.should.be.instanceof Array

4
test/ciao/suggest/nearby_nobias.coffee

@ -1,6 +1,6 @@
#> suggest without geo bias
path: '/suggest/nearby?input=a'
path: '/v1/suggest/nearby?input=a'
#? 400 bad request
response.statusCode.should.equal 400
response.statusCode.should.equal 400

4
test/ciao/suggest/success.coffee

@ -1,6 +1,6 @@
#> valid suggest query
path: '/suggest?input=a&lat=0&lon=0'
path: '/v1/suggest?input=a&lat=0&lon=0'
#? 200 ok
response.statusCode.should.equal 200
@ -13,4 +13,4 @@ json.date.should.be.within now-5000, now+5000
#? valid geojson
json.type.should.equal 'FeatureCollection'
json.features.should.be.instanceof Array
json.features.should.be.instanceof Array

4
test/ciao/suggest/success_nearby.coffee

@ -1,6 +1,6 @@
#> valid suggest query
path: '/suggest/nearby?input=a&lat=29.49136&lon=-82.50622'
path: '/v1/suggest/nearby?input=a&lat=29.49136&lon=-82.50622'
#? 200 ok
response.statusCode.should.equal 200
@ -13,4 +13,4 @@ json.date.should.be.within now-5000, now+5000
#? valid geojson
json.type.should.equal 'FeatureCollection'
json.features.should.be.instanceof Array
json.features.should.be.instanceof Array

Loading…
Cancel
Save