diff --git a/map4.js b/map4.js index 1220aa1..d0b0788 100644 --- a/map4.js +++ b/map4.js @@ -8,7 +8,7 @@ const supa = window.supabase.createClient(SUPABASE_URL, SUPABASE_KEY); // =================================== -// デバイスID +// デバイスID(ローカル保存) // =================================== let deviceId = localStorage.getItem("deviceId"); if (!deviceId) { @@ -30,7 +30,7 @@ const DEFAULT_LNG = 139.752799; // =================================== -// URL パラメータ +// URL パラメータ読み込み // =================================== function loadParams() { const p = new URLSearchParams(location.search); @@ -42,7 +42,7 @@ } // =================================== -// カスタムアイコン(ラベル無しに修正) +// ピンアイコン(常時ラベルなしの通常版) // =================================== function createIcon(type) { let pinImg = ""; @@ -75,7 +75,7 @@ } // =================================== -// 地図生成 +// 地図初期化 // =================================== function initMap(lat, lng) { map = L.map("map").setView([lat, lng], 15); @@ -86,7 +86,7 @@ } // =================================== -// 自分のピン(毎回再描画) +// 自分のピン描画(再描画方式) // =================================== function renderSelfMarker() { if (selfMarker) map.removeLayer(selfMarker); @@ -96,18 +96,18 @@ interactive: true, }).addTo(map); - // 吹き出し(名前は popup のみ表示) + // popupのみ selfMarker.bindPopup(`${currentUser}(あなた)`); - // ★ クリック 1 回で中央へ + // ★ 中央に確実に移動 selfMarker.on("click", () => { - map.setView([lastLat, lastLng], 17, { animate: true }); + map.panTo(selfMarker.getLatLng(), { animate: true, duration: 0.5 }); selfMarker.openPopup(); }); } // =================================== -// 自分の位置保存 +// 自分の位置を Supabase へ保存 // =================================== async function saveMyLocation(lat, lng) { await supa @@ -145,10 +145,9 @@ li.append(row.user_name); - // ★ メンバータップでピン中央へ li.addEventListener("click", () => { if (row.device_id === deviceId) { - map.setView([lastLat, lastLng], 17, { animate: true }); + map.panTo(selfMarker.getLatLng(), { animate: true, duration: 0.5 }); selfMarker.openPopup(); return; } @@ -156,7 +155,7 @@ const mk = otherMarkers.find((m) => m._myDeviceId === row.device_id); if (!mk) return; - map.setView([row.lat, row.lng], 17, { animate: true }); + map.panTo(mk.getLatLng(), { animate: true, duration: 0.5 }); mk.openPopup(); }); @@ -165,7 +164,7 @@ } // =================================== -// 他ユーザー描画 +// 他ユーザーのピン描画 // =================================== async function showOtherUsers() { const { data } = await supa @@ -198,9 +197,9 @@ mk.bindPopup(`${row.user_name}`); - // ★ 1クリックで中央へ + // ★ 中央へ確実に移動 mk.on("click", () => { - map.setView([row.lat, row.lng], 17, { animate: true }); + map.panTo(mk.getLatLng(), { animate: true, duration: 0.5 }); mk.openPopup(); }); @@ -232,6 +231,7 @@ await saveMyLocation(lat, lng); await showOtherUsers(); + // 自分の位置更新 setInterval(async () => { try { const pos = await getPosition(); @@ -243,6 +243,7 @@ } catch {} }, 8000); + // 他ユーザー更新 setInterval(showOtherUsers, 2000); const exit = document.getElementById("exitBtn");