function makeMap(zoomShape) {
const canvas = html`<canvas width=${width + "px"} height="${
mapHeight + "px"
}"></canvas>`;
const ctx = canvas.getContext("2d");
scaleCanvas(ctx.canvas, ctx);
let projection = mapProjection;
let path = d3.geoPath(projection).context(ctx);
function zoomed(transform) {
ctx.save();
ctx.clearRect(0, 0, mapWidth, mapHeight);
ctx.translate(transform.x, transform.y);
ctx.scale(transform.k, transform.k);
ctx.beginPath();
path(zoomShape);
ctx.stroke();
shapesWithData.forEach((d) => {
ctx.strokeStyle = "#ddd";
ctx.lineWidth = 0.25 / transform.k;
if (showCountyLines) {
ctx.beginPath();
path(d);
ctx.stroke();
}
if (d.points && d.points.features) {
d.points.features.forEach((feature) => {
const {
geometry: {
coordinates: [x, y]
}
} = feature;
let c = projection([x, y]);
if (!c) return;
const dotColor = d3.color(feature.properties.color);
dotColor.opacity = dotOpacity;
ctx.fillStyle = dotColor.toString();
ctx.fillRect(
c[0],
c[1],
demographicPointSize / transform.k,
demographicPointSize / transform.k
);
});
}
});
ctx.fillStyle = "#111";
ctx.beginPath();
ctx.font = "24px Helvetica";
ctx.fill();
ctx.fill();
ctx.restore();
}
zoomed(d3.zoomIdentity);
return ctx.canvas;
}