diff --git a/map4.js b/map4.js index 01c7594..43b2d5d 100644 --- a/map4.js +++ b/map4.js @@ -1,18 +1,25 @@ -// モジュール内スコープなのでグローバル汚染しない +// グローバル変数を作らないように IIFE + module を併用 (() => { - // マップ初期表示(皇居) - const map = L.map('map').setView([35.681236, 139.767125], 15); + // URLパラメータからグループ名取得 + const params = new URLSearchParams(window.location.search); + const groupName = params.get("group") || "未設定"; - // タイルレイヤー + // HTMLに表示 + document.getElementById("groupName").textContent = groupName; + + // 初期マップ(皇居あたり) + const map = L.map('map').setView([35.681236, 139.767125], 14); + + // OSMタイル L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { - attribution: '© OpenStreetMap contributors' + attribution: "© OpenStreetMap contributors" }).addTo(map); // 現在地へ移動する関数 function moveToCurrentLocation() { if (!navigator.geolocation) { - alert("このブラウザは位置情報に対応していません"); + alert("位置情報が取得できません。"); return; } @@ -22,21 +29,21 @@ const lng = pos.coords.longitude; // ふわっと移動 - map.flyTo([lat, lng], 17, { duration: 2 }); + map.flyTo([lat, lng], 17, { duration: 1.6 }); - // マーカー表示 + // マーカー追加 L.marker([lat, lng]) .addTo(map) - .bindPopup("あなたの現在地") + .bindPopup(`あなたの現在地
グループ:${groupName}`) .openPopup(); }, err => { - alert("現在地を取得できませんでした: " + err.message); + alert("位置情報の取得に失敗しました:" + err.message); } ); } - // ページ読み込み時に現在地へ移動 + // ページ読み込み時に発動 moveToCurrentLocation(); })();