Published
Edited
Mar 22, 2019
2 forks
1 star
Insert cell
Insert cell
Insert cell
Insert cell
h3Index = {
// Get all of the base cells for the initial iteration
const baseCells = h3.getRes0Indexes();
for (const index of baseCells) {
yield* await getChildrenAtRes(index, h3Res);
}
}
Insert cell
Insert cell
async function* getChildrenAtRes(h3Index, targetRes) {
const nextRes = h3.h3GetResolution(h3Index) + 1;
// Iterate over all direct children of the current index
for (const child of h3.h3ToChildren(h3Index, nextRes)) {
if (nextRes >= targetRes) {
await Promises.delay(300);
yield child;
} else {
yield* getChildrenAtRes(child, targetRes);
}
}
}
Insert cell
{
// Create a Polygon feature from the current hexagon and render on the map
const feature = {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [h3.h3ToGeoBoundary(h3Index, true)]
}
};
fixTransmeridian(feature);
map.getSource('hex-source').setData(feature);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more