function addPointToGrid(pt, grid) {
let res = 15;
const finest = h3.latLngToCell(pt[0], pt[1], res);
while (res >= 0) {
const cell = h3.cellToParent(finest, res);
if (cell in grid) {
grid[cell].push(finest);
if (grid[cell].length > maxPointsPerCell) {
const childRes = res + 1;
if (childRes <= 15) {
for (const child of h3.cellToChildren(cell, childRes)) {
grid[child] = [];
}
for (const fineCell of grid[cell]) {
const child = h3.cellToParent(fineCell, childRes);
grid[child].push(fineCell)
}
delete grid[cell];
}
}
break;
} else if (res === 0) {
grid[cell] = [finest];
break;
}
res--;
}
}