map = {
let canvas = d3.create("canvas").node();
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext("2d");
ctx.fillStyle = "#111";
ctx.fillRect(0, 0, width, height);
ctx.globalAlpha = 0.5;
let path = d3.geoPath(projection).context(ctx);
ctx.translate(width / 2, height / 2);
ctx.rotate((-90 * Math.PI) / 180);
ctx.translate(-width / 2, -height / 2);
ctx.strokeStyle = "#fff";
ctx.fillStyle = "#ccc";
ctx.beginPath();
path(polygons);
ctx.stroke();
ctx.strokeStyle = "#fff";
ctx.beginPath();
path(california);
ctx.stroke();
for (let sensor of filtered) {
let p = projection([sensor.Lon, sensor.Lat]);
ctx.fillStyle = colorPM1(sensor.pm_1);
ctx.fillRect(p[0], p[1], 3, 3);
}
ctx.globalAlpha = 1;
for (let city of cities) {
let p = projection([city.lng, city.lat]);
if (!p) continue;
ctx.fillStyle = "white";
ctx.font = "bold 10px sans-serif";
ctx.save();
ctx.translate(p[0], p[1]);
ctx.rotate((90 * Math.PI) / 180);
ctx.translate(-p[0], -p[1]);
ctx.fillText(city.city, p[0], p[1]);
ctx.restore();
}
return canvas;
}