diff --git a/lib/src/project.js b/lib/src/project.js index 1d88da47..e5225299 100644 --- a/lib/src/project.js +++ b/lib/src/project.js @@ -10,7 +10,7 @@ const fields = [ 'silverFirArea', 'relief', ]; -const fieldsConcat = ['slope', 'additional', 'silverFirArea', 'relief']; +const secondaryFields = ['slope', 'additional', 'silverFirArea', 'relief']; const concat = (x, y) => Array.from(new Set((x || []).concat(y))).sort((a, b) => a - b); @@ -40,7 +40,7 @@ function projectionReducer(location, targetAltitudePointer, result) { const { field, value, values } = getField(fields[i], location); validate(field, value, values); - options[field] = fieldsConcat.includes(field) + options[field] = secondaryFields.includes(field) ? concat(options[field], Object.keys(projection)) : options[field] || Object.keys(projection); @@ -52,10 +52,9 @@ function projectionReducer(location, targetAltitudePointer, result) { } else if (valueNotInOptions(value, options[field])) { // Do not return location values if no projection was found. return { ...result, options }; - } else if (fieldsConcat.includes(field)) { + } else if (secondaryFields.includes(field)) { // Fall back to first projection for secondary fields. - const first = Object.keys(projection)[0]; - projection = projection[first]; + projection = projection[options[field][0]]; } else { // Location does not provide any more values for conditions. break; @@ -117,7 +116,7 @@ function project(location = {}, targetAltitude, previousResult) { const transition = project(tl, targetAltitude); const tp = transition.projections || []; Object.entries(transition.options).forEach(([k, v]) => { - if (fieldsConcat.includes(k)) { + if (secondaryFields.includes(k)) { result.options[k] = concat(result.options[k], v); } });