Public
Edited
Nov 7, 2023
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
config = ({
lat: 20,
lng: 0,
zoom: 1,
points: 10_000,
delay: 500
});
Insert cell
{
renderH3IndexesToMap(map, 'hexes', hexagons, null, true)
return md`*{map rendering logic}*`
}
Insert cell
hexagons = {
const grid = {};

for (let i = 0; i < config.points; i++) {
await Promises.delay(config.delay, ++i);
const pt = [Math.random() * 179 - 90, Math.random() * 359 - 180];
addPointToGrid(pt, grid);
yield Object.keys(grid).filter(cell => grid[cell].length);
}
}
Insert cell
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) {
// Add to grid
grid[cell].push(finest);
// Subdivide if needed
if (grid[cell].length > maxPointsPerCell) {
const childRes = res + 1;
if (childRes <= 15) {
// Make a grid entry for each child
for (const child of h3.cellToChildren(cell, childRes)) {
grid[child] = [];
}
// Reallocate points to child cells
for (const fineCell of grid[cell]) {
const child = h3.cellToParent(fineCell, childRes);
grid[child].push(fineCell)
}
// Drop the parent
delete grid[cell];
}
}
break;
} else if (res === 0) {
grid[cell] = [finest];
break;
}
res--;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more