diff --git a/map4.js b/map4.js index 2e9e9db..956b3eb 100644 --- a/map4.js +++ b/map4.js @@ -605,7 +605,7 @@ } // =================================== -// 最寄り駅のピン(EV対応・駅名ゆれ吸収) +// 最寄り駅のピン(EV対応・駅名ゆれ吸収・「○○駅」表示) // =================================== async function loadStations() { if (!map || lastLat === null) return; @@ -627,44 +627,52 @@ let nearest = null; let nearestDist = Infinity; + // --------------------- + // ★ forEach の正しい開始 + // --------------------- stations.forEach((st) => { - // Overpass API の駅名 let name = st.tags?.name || "駅名不明"; - // ★ 駅名ゆれを吸収(末尾の「駅」を削除) + // 「駅」を削除して比較用にする const cleanName = name.replace(/駅$/, ""); const d = distanceMeters(lastLat, lastLng, st.lat, st.lon); - // 最寄駅更新 + // 最寄り駅更新 if (d < nearestDist) { - nearest = { - name: cleanName, // ← 加工後の駅名を保存 - lat: st.lat, - lng: st.lon + nearest = { + name: cleanName, + lat: st.lat, + lng: st.lon, }; nearestDist = d; } -// 通常ピン -const mk = L.marker([st.lat, st.lon]).addTo(map); -mk.bindPopup(cleanName + "駅"); // ← 表示は必ず「○○駅」 -stationMarkers.push(mk); -// EVピン -if (elevatorInfo.get(cleanName)) { - const ev = L.marker([st.lat, st.lon], { icon: elevatorIcon }) - .addTo(map) - .bindPopup(`${cleanName}駅:エレベーターあり`); - stationMarkers.push(ev); -} + // 通常駅ピン + const mk = L.marker([st.lat, st.lon]).addTo(map); + mk.bindPopup(cleanName + "駅"); // ← 表示は必ず「◯◯駅」 + stationMarkers.push(mk); + // EVピン(CSV一致した駅) + if (elevatorInfo.get(cleanName)) { + const ev = L.marker([st.lat, st.lon], { icon: elevatorIcon }) + .addTo(map) + .bindPopup(`${cleanName}駅:エレベーターあり`); + stationMarkers.push(ev); + } + }); + // --------------------- + // ★ forEach 正しく閉じる + // --------------------- - // 最寄駅の EV判定 - const evText = elevatorInfo.get(nearest.name) ? "(エレベーターあり)" : "(エレベーターなし)"; + // 最寄り駅の EV判定 + const evText = elevatorInfo.get(nearest.name) + ? "(エレベーターあり)" + : "(エレベーターなし)"; - // 最寄駅表示 + // 最寄り駅表示 box.textContent = - `最寄り駅:${nearest.name}${evText}駅(約 ${(nearestDist / 1000).toFixed(2)} km)`; + `最寄り駅:${nearest.name}駅 ${evText}(約 ${(nearestDist / 1000).toFixed(2)} km)`; } // =================================== // メイン処理