diff --git a/hokaku.js b/hokaku.js index b837220..b67711c 100644 --- a/hokaku.js +++ b/hokaku.js @@ -45,6 +45,11 @@ playerMarker = L.marker(map.getCenter()).addTo(map); playerMarker.bindPopup("STARTを押して探索開始").openPopup(); + + // ✅ ここで click を登録する + map.on("click", (e) => { + updateLocation(e.latlng); + }); } // ========================= @@ -99,18 +104,16 @@ } // ========================= - // 捕獲処理(ガチャ) + // 捕獲処理 // ========================= function captureMonster() { if (!canCapture || !monsterLatLng) return; const success = Math.random() < CAPTURE_RATE; - if (success) { - playerMarker.setPopupContent("🎉 捕獲成功!").openPopup(); - } else { - playerMarker.setPopupContent("💨 逃げられた…").openPopup(); - } + playerMarker.setPopupContent( + success ? "🎉 捕獲成功!" : "💨 逃げられた…" + ).openPopup(); if (monsterMarker) { map.removeLayer(monsterMarker); @@ -123,19 +126,14 @@ } // ========================= - // GPS 成功 + // GPS // ========================= function onSuccess(pos) { - const latlng = L.latLng( - pos.coords.latitude, - pos.coords.longitude + updateLocation( + L.latLng(pos.coords.latitude, pos.coords.longitude) ); - updateLocation(latlng); } - // ========================= - // GPS エラー - // ========================= function onError() { nTrial--; playerMarker @@ -149,9 +147,6 @@ } } - // ========================= - // 追跡制御 - // ========================= function startWatch() { stopWatch(); watchId = navigator.geolocation.watchPosition( @@ -178,11 +173,6 @@ stopBtn.addEventListener("click", stopWatch); captureBtn.addEventListener("click", captureMonster); - map.on("click", (e) => { - updateLocation(e.latlng); - }); - - // ========================= // 起動 // =========================