Skip to content

Commit

Permalink
rework band info creation to make sure output contains all selector vals
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane98c committed Feb 29, 2024
1 parent b9782db commit 1d897ce
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1d897ce

Please sign in to comment.