outputCellValues = {
const outputCells = new Map();
function getAnonymizingSum(cells) {
return cells.map(cell => popMap.get(cell) ?? 0).reduce((sum, val) => sum + val, 0);
}
for (const {lat, lng} of locations) {
let currentRes = h3Resolution;
let candidateSet = [h3.latLngToCell(lat, lng, currentRes)];
while (getAnonymizingSum(candidateSet) < populationThreshold && currentRes > 3) {
currentRes--;
const parentCell = h3.latLngToCell(lat, lng, currentRes);
candidateSet = h3.cellToChildren(parentCell, h3Resolution);
}
for (const cell of candidateSet) {
const currentValue = outputCells.get(cell) ?? 0;
outputCells.set(cell, currentValue + (1 / candidateSet.length))
}
}
return outputCells;
}