diff --git a/src/utils.js b/src/utils.js index ed5e5c5..8ea5e02 100644 --- a/src/utils.js +++ b/src/utils.js @@ -365,36 +365,35 @@ export const getPyramidMetadata = (multiscales) => { * @returns Object containing bandName, {[dimension]: dimensionValue} pairs */ export const getBandInformation = (selector) => { - const combinedBands = Object.keys(selector) - .filter((key) => Array.isArray(selector[key])) - .reduce((bandMapping, selectorKey) => { - const values = selector[selectorKey] - let keys - if (typeof values[0] === 'string') { - keys = values + const keys = Object.keys(selector).filter((key) => + Array.isArray(selector[key]) + ) + if (keys.length === 0) return {} + let combinedBands = {} + keys.forEach((key) => { + const newCombinedBands = {} + selector[key].forEach((value) => { + const valueKey = typeof value === 'string' ? value : key + '_' + value + if (Object.keys(combinedBands).length === 0) { + newCombinedBands[valueKey] = { [key]: value } } else { - keys = values.map((d) => selectorKey + '_' + d) + Object.keys(combinedBands).forEach((existingKey) => { + newCombinedBands[existingKey + '_' + valueKey] = { + ...combinedBands[existingKey], + [key]: value, + } + }) } - - const bands = Object.keys(bandMapping) - const updatedBands = {} - keys.forEach((key, i) => { - if (bands.length > 0) { - bands.forEach((band) => { - const bandKey = `${band}_${key}` - updatedBands[bandKey] = { - ...bandMapping[band], - [selectorKey]: values[i], - } - }) - } else { - updatedBands[key] = { [selectorKey]: values[i] } - } + }) + combinedBands = newCombinedBands + }) + Object.keys(selector).forEach((key) => { + if (!Array.isArray(selector[key])) { + Object.keys(combinedBands).forEach((combinedKey) => { + combinedBands[combinedKey][key] = selector[key] }) - - return updatedBands - }, {}) - + } + }) return combinedBands }