diff --git a/map.js b/map.js new file mode 100644 index 0000000..ee369ac --- /dev/null +++ b/map.js @@ -0,0 +1,49 @@ +// 地図の初期化 + const map = L.map('map').setView([38.9122, 139.8360], 13); + + // 国土地理院の地図タイルレイヤーを追加 + L.tileLayer('https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', { + attribution: '国土地理院', + maxZoom: 18, + minZoom: 5 + }).addTo(map); + + // 地図をクリックしてマーカーと情報ウィンドウを追加 + map.on('click', (e) => { + const { lat, lng } = e.latlng; + addMarker(lat, lng); + }); + + // マーカーとコメント入力ウィンドウを追加 + function addMarker(lat, lng) { + // マーカーの作成 + const marker = L.marker([lat, lng]).addTo(map); + + // ポップアップ(情報ウィンドウ)を作成 + const popupContent = ` +
+

活動日記を入力してください:

+ + +
+ `; + marker.bindPopup(popupContent).openPopup(); + } + + // コメントを保存し、右側の履歴に追加 + function saveComment(lat, lng) { + const comment = document.getElementById("comment").value; + const timestamp = new Date().toLocaleString(); // 現在日時を取得 + + // コメント履歴に追加するHTML要素を作成 + const commentEntry = ` +
+

日時: ${timestamp}

+

場所: 緯度 ${lat}, 経度 ${lng}

+

活動日記: ${comment}

+
+ `; + document.getElementById("comments-list").innerHTML += commentEntry; + + + }