|
|
@ -1,7 +1,9 @@ |
|
|
|
|
|
|
|
|
|
|
|
var GeoJSON = require('geojson'), |
|
|
|
var GeoJSON = require('geojson'); |
|
|
|
extent = require('geojson-extent'), |
|
|
|
var extent = require('geojson-extent'); |
|
|
|
outputGenerator = require('./outputGenerator'); |
|
|
|
var outputGenerator = require('./outputGenerator'); |
|
|
|
|
|
|
|
var logger = require('pelias-logger').get('api'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Properties to be copied when details=true
|
|
|
|
// Properties to be copied when details=true
|
|
|
|
var DETAILS_PROPS = [ |
|
|
|
var DETAILS_PROPS = [ |
|
|
@ -19,20 +21,62 @@ var DETAILS_PROPS = [ |
|
|
|
'neighbourhood' |
|
|
|
'neighbourhood' |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
var META_MAP = { |
|
|
|
|
|
|
|
'geoname': { type: '???', source: 'gn' }, // TODO: not sure how to map. will need to use categories?
|
|
|
|
var SOURCES = { |
|
|
|
'osmnode': { type: 'venue', source: 'osm' }, |
|
|
|
'geoname': 'gn', |
|
|
|
'osmway': { type: 'venue', source: 'osm' }, |
|
|
|
'osmnode': 'osm', |
|
|
|
'admin0': { type: 'country', source: 'qs' }, |
|
|
|
'osmway': 'osm', |
|
|
|
'admin1': { type: 'region', source: 'qs' }, |
|
|
|
'admin0': 'qs', |
|
|
|
'admin2': { type: 'county', source: 'qs' }, |
|
|
|
'admin1': 'qs', |
|
|
|
'neighborhood': { type: 'neighbourhood', source: 'qs' }, |
|
|
|
'admin2': 'qs', |
|
|
|
'locality': { type: 'locality', source: 'qs' }, |
|
|
|
'neighborhood': 'qs', |
|
|
|
'local_admin': { type: 'local_admin', source: 'qs' }, |
|
|
|
'locality': 'qs', |
|
|
|
'osmaddress': { type: 'address', source: 'osm' }, |
|
|
|
'local_admin': 'qs', |
|
|
|
'openaddresses': { type: 'address', source: 'oa' } |
|
|
|
'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 'local_admin'; |
|
|
|
|
|
|
|
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 ){ |
|
|
|
function geojsonifyPlaces( docs, params ){ |
|
|
|
|
|
|
|
|
|
|
|
var details = params ? params.details : {}; |
|
|
|
var details = params ? params.details : {}; |
|
|
@ -148,12 +192,9 @@ function copyProperties( source, props, dst ) { |
|
|
|
* @param {object} dst |
|
|
|
* @param {object} dst |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function addMetaData(src, 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.id = src._id; |
|
|
|
dst.layer = meta.type; |
|
|
|
dst.layer = lookupLayer(src); |
|
|
|
dst.source = meta.source; |
|
|
|
dst.source = lookupSource(src); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|