Browse Source

refactored for lodash because its siren song is so sweet

pull/899/head
Stephen Hess 8 years ago
parent
commit
788a8c8069
  1. 27
      controller/coarse_reverse.js

27
controller/coarse_reverse.js

@ -18,6 +18,7 @@ const coarse_granularities = [
// remove non-coarse layers and return what's left (or all if empty) // remove non-coarse layers and return what's left (or all if empty)
function getEffectiveLayers(requested_layers) { function getEffectiveLayers(requested_layers) {
// remove non-coarse layers
const non_coarse_layers_removed = _.without(requested_layers, 'venue', 'address', 'street'); const non_coarse_layers_removed = _.without(requested_layers, 'venue', 'address', 'street');
// if resulting array is empty, use all coarse granularities // if resulting array is empty, use all coarse granularities
@ -62,30 +63,32 @@ function synthesizeDoc(results) {
const doc = new Document('whosonfirst', most_granular_layer, id.toString()); const doc = new Document('whosonfirst', most_granular_layer, id.toString());
doc.setName('default', results[most_granular_layer][0].name); doc.setName('default', results[most_granular_layer][0].name);
if (results[most_granular_layer][0].hasOwnProperty('centroid')) { // assign the administrative hierarchy
_.keys(results).forEach((layer) => {
doc.addParent(layer, results[layer][0].name, results[layer][0].id.toString(), results[layer][0].abbr);
});
// set centroid if available
if (_.has(results[most_granular_layer][0], 'centroid')) {
doc.setCentroid( results[most_granular_layer][0].centroid ); doc.setCentroid( results[most_granular_layer][0].centroid );
} }
if (results[most_granular_layer][0].hasOwnProperty('bounding_box')) { // set bounding box if available
const parsedBoundingBox = results[most_granular_layer][0].bounding_box.split(',').map(parseFloat); if (_.has(results[most_granular_layer][0], 'bounding_box')) {
const parsed_bounding_box = results[most_granular_layer][0].bounding_box.split(',').map(parseFloat);
doc.setBoundingBox({ doc.setBoundingBox({
upperLeft: { upperLeft: {
lat: parsedBoundingBox[3], lat: parsed_bounding_box[3],
lon: parsedBoundingBox[0] lon: parsed_bounding_box[0]
}, },
lowerRight: { lowerRight: {
lat: parsedBoundingBox[1], lat: parsed_bounding_box[1],
lon: parsedBoundingBox[2] lon: parsed_bounding_box[2]
} }
}); });
} }
// assign the administrative hierarchy
Object.keys(results).forEach((layer) => {
doc.addParent(layer, results[layer][0].name, results[layer][0].id.toString(), results[layer][0].abbr);
});
const esDoc = doc.toESDocument(); const esDoc = doc.toESDocument();
esDoc.data._id = esDoc._id; esDoc.data._id = esDoc._id;
esDoc.data._type = esDoc._type; esDoc.data._type = esDoc._type;

Loading…
Cancel
Save