実際のシステムがどのような仕組みかは分かりませんが、
スマホアプリ同様にタップ等の制御可能という事は分かりました。
#Sペンでは、2つめの四角以外反応しない。
もう少し深堀をしたいところですが、
(touch,pen,mouseに該当する条件って、具体的に何?とか)
端末だけでなくブラウザやOSによっても色々異なるとの記述もあり根が深そうです。
動作確認をしたコード
HTML
1<canvas id="seatCanvas" width="600" height="200"></canvas>
2<div id="message">座席を選択してください</div>
CSS
1body { text-align: center; font-family: sans-serif; }
2canvas { border: 1px solid #333; margin: 20px auto; display: block; }
3#message { font-size: 18px; color: green; }
JS
1const canvas = document.getElementById('seatCanvas');
2const ctx = canvas.getContext('2d');
3const messageDiv = document.getElementById('message');
4
5const seats = [
6 { x: 50, y: 50, w: 100, h: 100, color: 'lightgray', reserved: false, allowedType: 'touch' },
7 { x: 250, y: 50, w: 100, h: 100, color: 'lightgray', reserved: false, allowedType: 'pen' },
8 { x: 450, y: 50, w: 100, h: 100, color: 'lightgray', reserved: false, allowedType: 'mouse' }
9];
10
11function drawSeats() {
12 ctx.clearRect(0, 0, canvas.width, canvas.height);
13 seats.forEach((seat, i) => {
14 ctx.fillStyle = seat.color;
15 ctx.fillRect(seat.x, seat.y, seat.w, seat.h);
16 ctx.strokeRect(seat.x, seat.y, seat.w, seat.h);
17 ctx.fillStyle = 'black';
18 ctx.font = '20px sans-serif';
19 ctx.fillText(`座席 ${i+1}`, seat.x+15, seat.y+60);
20 });
21}
22
23function getSeatIndex(x, y) {
24 return seats.findIndex(s => x>=s.x && x<=s.x+s.w && y>=s.y && y<=s.y+s.h);
25}
26
27canvas.addEventListener('pointerdown', e => {
28 const rect = canvas.getBoundingClientRect();
29 const x = e.clientX - rect.left;
30 const y = e.clientY - rect.top;
31 const idx = getSeatIndex(x, y);
32 if (idx === -1) return;
33 const seat = seats[idx];
34 if (e.pointerType === seat.allowedType) {
35 seat.reserved = !seat.reserved;
36 seat.color = seat.reserved
37 ? (seat.allowedType==='touch'?'lightblue':seat.allowedType==='pen'?'lightgreen':'orange')
38 : 'lightgray';
39 messageDiv.textContent = seat.reserved
40 ? `座席 ${idx+1} が予約されました(${e.pointerType})`
41 : `座席 ${idx+1} の予約がキャンセルされました`;
42 drawSeats();
43 } else {
44 messageDiv.textContent = `座席 ${idx+1} は ${seat.allowedType} でのみ予約可能です(現在: ${e.pointerType})`;
45 }
46});
47
48drawSeats();