canvas = {
const ctx = DOM.context2d(width, height);
ctx.canvas.style.background = "hsl(216deg 20% 90%)";
const img = new Image();
img.src = select == "Road" ? backgroundImage.src : satelliteImage.src;
img.setAttribute("crossOrigin", "");
img.onload = () => {
ctx.canvas.onmousedown = (e) => {
console.log("Click", e);
origPtr.origPtrX = e.offsetX;
origPtr.origPtrY = e.offsetY;
draw();
};
draw();
function draw() {
const { fineWidth, fineHeight, roughWidth, roughHeight } = gridSet;
const { origPtrX, origPtrY } = origPtr;
const { roughColor, fineColor, origColor, rotate } = form;
ctx.drawImage(img, 0, 0, width, height);
{
ctx.save();
const width2 = width * 3,
height2 = height * 3;
ctx.translate(origPtrX, origPtrY);
ctx.rotate(rotate);
ctx.translate(-width / 2, -height / 2);
for (let x = width / 2; x < width2; x += fineWidth) {
ctx.strokeStyle = fineColor;
ctx.lineWidth = 1;
ctx.beginPath(),
ctx.moveTo(x, -height2),
ctx.lineTo(x, height2),
ctx.stroke();
ctx.beginPath(),
ctx.moveTo(width - x, -height2),
ctx.lineTo(width - x, height2),
ctx.stroke();
}
for (let y = height / 2; y < height2; y += fineHeight) {
ctx.strokeStyle = fineColor;
ctx.lineWidth = 1;
ctx.beginPath(),
ctx.moveTo(-width2, y),
ctx.lineTo(width2, y),
ctx.stroke();
ctx.beginPath(),
ctx.moveTo(-width2, height - y),
ctx.lineTo(width2, height - y),
ctx.stroke();
}
for (let x = width / 2; x < width2; x += roughWidth) {
ctx.strokeStyle = roughColor;
ctx.lineWidth = 2;
ctx.beginPath(),
ctx.moveTo(x, -height2),
ctx.lineTo(x, height2),
ctx.stroke();
ctx.beginPath(),
ctx.moveTo(width - x, -height2),
ctx.lineTo(width - x, height2),
ctx.stroke();
}
for (let y = height / 2; y < height2; y += roughHeight) {
ctx.strokeStyle = roughColor;
ctx.lineWidth = 2;
ctx.beginPath(),
ctx.moveTo(-width2, y),
ctx.lineTo(width2, y),
ctx.stroke();
ctx.beginPath(),
ctx.moveTo(-width2, height - y),
ctx.lineTo(width2, height - y),
ctx.stroke();
}
ctx.fillStyle = origColor;
ctx.rect(width / 2 - 5, height / 2 - 5, 10, 10);
ctx.fill();
ctx.restore();
}
}
};
return ctx.canvas;
}