mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
58 lines
1.2 KiB
8 years ago
|
/**
|
||
|
*
|
||
|
* Accuracy level should be set for each item in the results.
|
||
|
* The level can be any of the following:
|
||
|
* - point
|
||
|
* - interpolated
|
||
|
* - centroid
|
||
|
*/
|
||
|
|
||
|
var check = require('check-types');
|
||
|
|
||
|
var accuracyLevel_point = 'point';
|
||
|
var accuracyLevel_interpolated = 'interpolated';
|
||
|
var accuracyLevel_centroid = 'centroid';
|
||
|
|
||
|
|
||
|
function setup() {
|
||
|
return computeAccuracy;
|
||
|
}
|
||
|
|
||
|
function computeAccuracy(req, res, next) {
|
||
|
// do nothing if no result data set
|
||
|
if (check.undefined(res) || check.undefined(res.data)) {
|
||
|
return next();
|
||
|
}
|
||
|
|
||
|
// loop through data items and determine accuracy levels
|
||
|
res.data = res.data.map(computeAccuracyLevelForResult);
|
||
|
|
||
|
next();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine accuracy level based on the type of result being returned.
|
||
|
*
|
||
|
* @param {object} hit
|
||
|
* @returns {object}
|
||
|
*/
|
||
|
function computeAccuracyLevelForResult(hit) {
|
||
|
|
||
|
// TODO: add a check for interpolated addresses when that feature lands
|
||
|
|
||
|
switch (hit.layer) {
|
||
|
case 'venue':
|
||
|
case 'address':
|
||
|
hit.accuracy = accuracyLevel_point;
|
||
|
break;
|
||
|
// this means it's a street or admin area
|
||
|
default:
|
||
|
hit.accuracy = accuracyLevel_centroid;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
return hit;
|
||
|
}
|
||
|
|
||
|
module.exports = setup;
|