diff --git a/map4.js b/map4.js index 2e63a21..0b1ecbf 100644 --- a/map4.js +++ b/map4.js @@ -66,10 +66,11 @@ // =================================== let elevatorInfo = new Map(); +// elevators.csv は map4.js / map4.html と同じフォルダ想定 fetch("./elevators.csv") .then((res) => res.text()) .then((text) => { - const lines = text.split("\n").slice(1); + const lines = text.split("\n").slice(1); // 1行目ヘッダ除外 lines.forEach((line) => { if (!line.trim()) return; @@ -80,11 +81,12 @@ console.log("EVデータ読み込み成功:", elevatorInfo); }); -// エレベーターアイコン(※後で絶対パスに直す) +// 画像は一旦保留(今は未使用だが残しておく) const elevatorIcon = L.icon({ iconUrl: "./elevator.png", iconSize: [22, 22], }); + // =================================== // URL パラメータ読み込み // =================================== @@ -176,6 +178,7 @@ status: myStatus, }); } + // =================================== // 待ち合わせピンアイコン // =================================== @@ -257,12 +260,15 @@ showDistanceToTarget(); } +// =================================== +// 距離計算(修正版) +// =================================== function distanceMeters(lat1, lng1, lat2, lng2) { const R = 6371000; const toRad = (deg) => (deg * Math.PI) / 180; const dLat = toRad(lat2 - lat1); - const dLng = toRad(lng2 - lng1); // ← ここを lng2 - lng1 に変更! + const dLng = toRad(lng2 - lng1); // ← ここが大事! const a = Math.sin(dLat / 2) ** 2 + @@ -285,6 +291,7 @@ document.getElementById("targetInfo").innerHTML = `待ち合わせ場所まで 約 ${km} km`; } + // =================================== // メンバー状態カラー // =================================== @@ -488,6 +495,7 @@ input.value = ""; loadMessages(); } + // =================================== // ホスト自動交代 // =================================== @@ -634,13 +642,27 @@ mk.bindPopup(name + "駅"); stationMarkers.push(mk); - // 🔵 EVピン(CSV と名前一致) + // EVありの駅 → 赤丸で表示(画像なしバージョン) if (elevatorInfo.get(name)) { - // 最寄り駅表示(EV情報つき) -const evText = elevatorInfo.get(nearest.name) ? "(EVあり)" : "(EVなし)"; + const ev = L.circleMarker([st.lat, st.lon], { + radius: 8, + color: "red", + fillColor: "red", + fillOpacity: 0.9, + }) + .addTo(map) + .bindPopup(`${name}:エレベーターあり`); -box.textContent = - `最寄り駅:${nearest.name}${evText}(約 ${(nearestDist / 1000).toFixed(2)} km)`; + stationMarkers.push(ev); + } + }); + + // 最寄り駅表示(EV情報つき) + const evText = elevatorInfo.get(nearest.name) ? "(EVあり)" : "(EVなし)"; + + box.textContent = + `最寄り駅:${nearest.name}${evText}(約 ${(nearestDist / 1000).toFixed(2)} km)`; +} // =================================== // メイン処理 @@ -650,7 +672,8 @@ setupStatusButtons(); // デフォルト位置:皇居 - let lat = 35.681236, lng = 139.767125; + let lat = 35.681236, + lng = 139.767125; // 現在位置を取得 try { @@ -684,7 +707,7 @@ loadStations(); // ------------------------------ - // ▼ 定期更新(高速リアルタイム)▼ + // ▼ 定期更新 ▼ // ------------------------------ // GPS更新