diff --git a/map4.js b/map4.js index f049bc7..6fa1f23 100644 --- a/map4.js +++ b/map4.js @@ -211,18 +211,18 @@ selfMarker.addTo(map); } // =================================== -// メンバー一覧(差分更新でチラつき防止) +// メンバー一覧(チカチカ完全防止版) // =================================== function showMemberList(latestByDevice) { const list = document.getElementById("memberList"); - // ① 既存の
  • を map に + // 既存の
  • を deviceId => li に変換 const exist = {}; Array.from(list.children).forEach(li => { exist[li.dataset.deviceId] = li; }); - // ② 今オンラインの人を処理 + // 今オンラインの人を処理 Object.values(latestByDevice).forEach(row => { const id = row.device_id; const diff = (Date.now() - new Date(row.updated_at)) / 1000; @@ -231,47 +231,43 @@ let li = exist[id]; if (!li) { - // 初登場 → 新規作成 + // 初登場 → 新規作成(順番はそのまま追加:並び替えしない) li = document.createElement("li"); li.dataset.deviceId = id; + li.className = "member-item"; - const icon = document.createElement("div"); - icon.className = "member-icon"; - li.appendChild(icon); - - const name = document.createElement("span"); - name.className = "member-name"; - li.appendChild(name); - - const status = document.createElement("span"); - status.className = "status-text"; - li.appendChild(status); + li.innerHTML = ` +
    + + + `; list.appendChild(li); } - // 色 - const color = id === deviceId ? "#58c16b" : "#FFD700"; - li.querySelector(".member-icon").style.background = color; + // 色だけ変更(レイアウトに影響しない) + li.querySelector(".member-icon").style.background = + id === deviceId ? "#58c16b" : "#FFD700"; - // 名前 + // 名前更新 li.querySelector(".member-name").textContent = row.user_name; - // オンライン・オフライン + // オンライン/オフラインの文字だけ更新 + li.querySelector(".member-status").textContent = + online ? "🟢" : "🔴"; + + // クラスの変更(CSSで色のみ変化させる) li.classList.toggle("online", online); li.classList.toggle("offline", !online); - li.querySelector(".status-text").textContent = - online ? "🟢オンライン" : "🔴オフライン"; - // 既存マップから削除(処理済み) + // 処理済みの existing エントリを削除 delete exist[id]; }); - // ③ 存在しなくなった人だけ削除 + // もう存在しない人を削除 Object.values(exist).forEach(li => li.remove()); } - // =================================== // 他ユーザー取得 // ===================================