function map() {
const context = DOM.context2d(width, height);
context.fillStyle = fillBackground;
context.fillRect(0, 0, width, height);
const projection = d3.geoIdentity().fitExtent(
[
[0, 0],
[width, height]
],
nation
);
const path = d3.geoPath(projection, context);
context.beginPath();
path(nation);
context.fillStyle = fillNation;
context.fill();
context.stroke();
context.clip();
context.beginPath();
path(states);
context.lineWidth = 0.75;
context.stroke();
context.lineWidth = 0.25;
for (const { fill, mult, layer } of [
{ fill: fillRegion, mult: 8 },
{ fill: fillZone, mult: 2.5, layer: true },
{ fill: fillCity, mult: 1 }
]) {
context.beginPath();
for (const { lon, lat, population } of cities) {
const r = mult * cityRadius(population) * scale;
const a = albers([lon, lat]);
if (!a) continue;
const p = projection(a);
context.moveTo(p[0] + r, p[1]);
context.arc(...p, r, 0, 2 * Math.PI);
}
context.fillStyle = fill;
context.fill();
context.strokeStyle = fill;
context.stroke();
if (layer) {
context.beginPath();
path(counties);
context.lineWidth = 0.25;
context.strokeStyle = "black";
context.stroke();
}
}
return context.canvas;
}