diff --git a/map4.js b/map4.js index c84cdf3..179a882 100644 --- a/map4.js +++ b/map4.js @@ -3,8 +3,7 @@ // =================================== const SUPABASE_URL = "https://ogtlmtnjkpsxsqzqlacj.supabase.co"; const SUPABASE_KEY = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9ndGxtdG5qa3BzeHNxenFsYWNqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjMyOTU3NjUsImV4cCI6MjA3ODg3MTc2NX0.JnCE7oUQwrSgGqiu-QRbwnaLBZrO8JX1_RUb37VIMFI"; - + "eyJhbGciOiJIUzI1NiIsInR5cCI...(省略)"; const supa = window.supabase.createClient(SUPABASE_URL, SUPABASE_KEY); // =================================== @@ -24,25 +23,23 @@ let map; let selfMarker = null; let otherMarkers = []; -let latestByDevice = {}; +let latestByDevice = []; let allMembers = []; let lastLat = null; let lastLng = null; let targetMarker = null; -let stationMarkers = []; let targetLat = null; let targetLng = null; -// -------------------------------------- -// ステータス:デフォルトは「移動中」 -// -------------------------------------- -let myStatus = localStorage.getItem("myStatus") || "移動中"; +let stationMarkers = []; // =================================== -// ステータス保存 +// ステータス:デフォルトは「移動中」 // =================================== +let myStatus = localStorage.getItem("myStatus") || "移動中"; + async function updateStatus(newStatus) { myStatus = newStatus; localStorage.setItem("myStatus", newStatus); @@ -56,33 +53,15 @@ showOtherUsers(); } -// =================================== -// ステータスボタン -// =================================== function setupStatusButtons() { const buttons = document.querySelectorAll(".stBtn"); - buttons.forEach((btn) => { - btn.addEventListener("click", () => { - const newStatus = btn.dataset.status; - updateStatus(newStatus); - }); - }); + buttons.forEach((btn) => + btn.addEventListener("click", () => updateStatus(btn.dataset.status)) + ); } // =================================== -// 待ち合わせピン -// =================================== -const meetIcon = L.icon({ - iconUrl: - "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-violet.png", - shadowUrl: - "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png", - iconSize: [25, 41], - iconAnchor: [12, 41], -}); - -// =================================== -// URL パラメータ +// URL パラメータ読み込み // =================================== function loadParams() { const p = new URLSearchParams(location.search); @@ -97,7 +76,7 @@ } // =================================== -// 位置取得 +// 現在位置取得 // =================================== function getPosition() { return new Promise((resolve, reject) => { @@ -119,7 +98,7 @@ maxZoom: 19, }).addTo(map); - // ホストのみ待ち合わせ設定 + // ホストのみ待ち合わせを設定 map.on("click", async (e) => { if (!isHost) return; @@ -149,41 +128,18 @@ } // =================================== -// 自位置保存(ステータス含む) +// ピン作成 // =================================== -async function saveMyLocation(lat, lng) { - await supa - .from("locations") - .delete() - .eq("group_name", currentGroup) - .eq("device_id", deviceId); +const meetIcon = L.icon({ + iconUrl: + "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-violet.png", + shadowUrl: + "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png", + iconSize: [25, 41], + iconAnchor: [12, 41], +}); - await supa.from("locations").insert({ - group_name: currentGroup, - user_name: currentUser, - device_id: deviceId, - lat, - lng, - status: myStatus, - }); -} - -// =================================== -// 自ピン表示 -// =================================== -function renderSelfMarker() { - if (!map || lastLat === null || lastLng === null) return; - - if (selfMarker) map.removeLayer(selfMarker); - - // ★ 修正:status を渡す - selfMarker = createLabeledMarker(lastLat, lastLng, currentUser, true, myStatus); - selfMarker.addTo(map); -} - -// =================================== -// ピン生成(ステータス色付き) -// =================================== +// 自分のピン色 function createLabeledMarker(lat, lng, name, isSelf, status) { const pinUrl = isSelf ? "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-green.png" @@ -200,11 +156,14 @@