diff --git a/shonaisinisemaptansaku.js b/shonaisinisemaptansaku.js deleted file mode 100644 index 2dcd119..0000000 --- a/shonaisinisemaptansaku.js +++ /dev/null @@ -1,257 +0,0 @@ -document.addEventListener("DOMContentLoaded", () => { - var mymap = L.map("locationmap").setView([38.855235,139.910744], 16); - - L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', { - attribution: '© OpenStreetMap contributors' - }).addTo(mymap); - - var playerIcon = L.icon({ - iconUrl: 'images/yuusya.png', - iconSize: [40, 40], - iconAnchor: [20, 40], - popupAnchor: [0, -40] - }); - - var locmarker = L.marker(mymap.getCenter(), { icon: playerIcon }).addTo(mymap); - locmarker.bindPopup("STARTを押してね").openPopup(); - - let circleRadius = 500; - let goalReachRadius = 10; // 赤サークル半径 - - var radiusCircle = L.circle(mymap.getCenter(), { - radius: circleRadius, - color: 'blue', - fillColor: 'blue', - fillOpacity: 0.1 - }).addTo(mymap); - - var watchId = null; - - const urlParams = new URLSearchParams(window.location.search); - const cheatMode = urlParams.get("cheat") === "true"; - - let stores = []; - let visitedStores = []; - let storeMarkers = []; - - function saveProgress() { - localStorage.setItem("visitedStores", JSON.stringify(visitedStores)); - } - - function loadProgress() { - const saved = localStorage.getItem("visitedStores"); - if (saved) { - try { - const parsed = JSON.parse(saved); - if (Array.isArray(parsed)) visitedStores = parsed; - } catch (e) { console.error("保存データの読み込みに失敗:", e); } - } - } - - function loadCSV() { - fetch('shonaisinisemap.csv') - .then(res => res.ok ? res.text() : Promise.reject("CSV読み込み失敗")) - .then(csvText => { - const results = Papa.parse(csvText, { header:true, skipEmptyLines:true }); - stores = results.data.map(item => ({ - name: item.name, - latitude: parseFloat(item.latitude), - longitude: parseFloat(item.longitude), - osusume: item.osusume || "", - iconUrl: item.icon || 'store.png', - marker: null, - redCircle: null - })).filter(s => !isNaN(s.latitude) && !isNaN(s.longitude)); - - visitedStores.forEach(obj => { - const s = stores.find(st => st.name === obj.name); - if (s) { - const customIcon = L.icon({ - iconUrl: s.iconUrl, - iconSize: [40, 40], - iconAnchor: [20, 40], - popupAnchor: [0, -40] - }); - let storeMarker = L.marker([s.latitude, s.longitude], { icon: customIcon }) - .addTo(mymap) - .bindPopup(`訪問日時: ${obj.time}
庄内総合高校の子のおすすめは${obj.osusume || "〇〇"}`); - storeMarkers.push(storeMarker); - } - }); - - if (cheatMode) { - document.getElementById("title").textContent = "チートモード"; - mymap.on("click", e => updateLocation(e.latlng)); - } - }) - .catch(err => alert("CSVの読み込みに失敗しました: " + err)); - } - - function getDistance(lat1, lng1, lat2, lng2) { - return L.latLng(lat1,lng1).distanceTo(L.latLng(lat2,lng2)); - } - - function getNearestStore(latlng) { - let nearest = null, minDist = Infinity; - for (let s of stores) { - if (visitedStores.some(c => c.name === s.name)) continue; - let d = getDistance(latlng.lat, latlng.lng, s.latitude, s.longitude); - if (d < minDist) { minDist = d; nearest = s; } - } - if (!nearest) return null; - return { store: nearest, distance: minDist }; - } - - function updateLocation(latlng) { - mymap.panTo(latlng); - locmarker.setLatLng(latlng); - radiusCircle.setLatLng(latlng); - - stores.forEach(s => { - const d = getDistance(latlng.lat, latlng.lng, s.latitude, s.longitude); - - if (visitedStores.some(c => c.name === s.name)) { - if (s.marker && mymap.hasLayer(s.marker)) mymap.removeLayer(s.marker); - if (s.redCircle && mymap.hasLayer(s.redCircle)) mymap.removeLayer(s.redCircle); - return; - } - - if (d <= circleRadius) { - if (!s.marker) { - s.marker = L.marker([s.latitude, s.longitude]).addTo(mymap).bindPopup(s.name); - } else if (!mymap.hasLayer(s.marker)) { - s.marker.addTo(mymap); - } - - if (!s.redCircle) { - s.redCircle = L.circle([s.latitude, s.longitude], { - radius: goalReachRadius, - color: 'red', - fillColor: 'red', - fillOpacity: 0.3 - }).addTo(mymap); - } else { - s.redCircle.setRadius(goalReachRadius); - if (!mymap.hasLayer(s.redCircle)) { - s.redCircle.addTo(mymap); - } - } - } else { - if (s.marker && mymap.hasLayer(s.marker)) mymap.removeLayer(s.marker); - if (s.redCircle && mymap.hasLayer(s.redCircle)) mymap.removeLayer(s.redCircle); - } - }); - - let nearestData = getNearestStore(latlng); - if (!nearestData) { - locmarker.setPopupContent("すべての店舗を訪問しました!").openPopup(); - return; - } - - const { store, distance } = nearestData; - - if (distance <= goalReachRadius) { - const now = new Date(); - const options = { - year: 'numeric', month: 'long', day: 'numeric', - weekday: 'long', hour: '2-digit', minute: '2-digit' - }; - const visitTime = now.toLocaleString('ja-JP', options); - const recommendation = store.osusume.trim() !== "" ? store.osusume : "〇〇"; - - locmarker.setPopupContent( - `到着!(${store.name})
訪問日時: ${visitTime}
庄内総合高校の子のおすすめは${recommendation}` - ).openPopup(); - - visitedStores.push({ name: store.name, time: visitTime, osusume: recommendation }); - saveProgress(); - - if (store.marker && mymap.hasLayer(store.marker)) mymap.removeLayer(store.marker); - if (store.redCircle && mymap.hasLayer(store.redCircle)) mymap.removeLayer(store.redCircle); - - const customIcon = L.icon({ - iconUrl: store.iconUrl, - iconSize: [40, 40], - iconAnchor: [20, 40], - popupAnchor: [0, -40] - }); - - let newMarker = L.marker([store.latitude, store.longitude], { icon: customIcon }) - .addTo(mymap) - .bindPopup(`訪問日時: ${visitTime}
庄内総合高校の子のおすすめは${recommendation}`); - storeMarkers.push(newMarker); - - } else if (distance <= circleRadius) { - locmarker.setPopupContent(`もう少しで${store.name}!`).openPopup(); - } else { - locmarker.setPopupContent(`ここは lat=${latlng.lat.toFixed(5)}, lng=${latlng.lng.toFixed(5)} です.`).openPopup(); - } - } - - function resetProgress() { - if (confirm("進行状況をリセットして最初からやり直しますか?")) { - localStorage.removeItem("visitedStores"); - visitedStores = []; - storeMarkers.forEach(m => mymap.removeLayer(m)); - storeMarkers = []; - alert("進行状況をリセットしました。"); - location.reload(); - } - } - - loadProgress(); - loadCSV(); - - if (!cheatMode) { - document.getElementById("start").addEventListener("click", () => { - watchId = navigator.geolocation.watchPosition( - pos => updateLocation(L.latLng(pos.coords.latitude,pos.coords.longitude)), - err => console.log(err), - { maximumAge:0, timeout:3000, enableHighAccuracy:true } - ); - }); - } - - document.getElementById("stop").addEventListener("click", () => { - if (watchId != null) navigator.geolocation.clearWatch(watchId); - watchId = null; - }); - document.getElementById("reset").addEventListener("click", resetProgress); - - // === セレクトボックス処理 === - const radiusSelect = document.getElementById("radiusSelect"); - const goalSelect = document.getElementById("goalSelect"); - const RADIUS_KEY = "selectedRadius"; - const GOAL_KEY = "selectedGoal"; - - let savedRadius = localStorage.getItem(RADIUS_KEY); - if (savedRadius) { - circleRadius = parseInt(savedRadius, 10); - radiusCircle.setRadius(circleRadius); - radiusSelect.value = savedRadius; - } - - let savedGoal = localStorage.getItem(GOAL_KEY); - if (savedGoal) { - goalReachRadius = parseInt(savedGoal, 10); - goalSelect.value = savedGoal; - } - - radiusSelect.addEventListener("change", (e) => { - circleRadius = parseInt(e.target.value, 10); - radiusCircle.setRadius(circleRadius); - localStorage.setItem(RADIUS_KEY, circleRadius); - }); - - goalSelect.addEventListener("change", (e) => { - goalReachRadius = parseInt(e.target.value, 10); - localStorage.setItem(GOAL_KEY, goalReachRadius); - - // 追加: すでにある赤サークルをすぐ更新 - stores.forEach(s => { - if (s.redCircle) { - s.redCircle.setRadius(goalReachRadius); - } - }); - }); -});