data = {
const position = []
const cdata = []
const maxCO2 = d3.max(envData.filter(x => countries.features.some(f => f.properties.name === x.country)), x => +x.co2_per_capita)
for (const feature of countries.features) {
let coordinates;
if (feature.geometry.type == "Polygon") {
coordinates = feature.geometry.coordinates
} else if (feature.geometry.type == "MultiPolygon") {
coordinates = feature.geometry.coordinates[0]
} else {
throw `All elements must be polygons or multipolgyons. ${feature.geometry}`
}
const center = (() => {
const centers = coordinates.map(coords =>
[
d3.mean(coords, x => x[0]),
d3.mean(coords, x => x[1]),
]
)
return centers[0]
})();
if (feature.id) {
cdata.push({ center, id: +feature.id })
}
}
return {
position: gl.regl.buffer(cdata.map(x => polarToCartesian(x.center[0], x.center[1], 1 + 0.01))),
countryIndex: gl.regl.buffer({
data: cdata.map(x => {
const u = Math.floor(x.id / 32)
const v = x.id - (u * 32)
return [v / 32, u / 32]
})
}),
count: cdata.length,
}
}