<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>いきいきMAP</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"/>
<style>
/* Base Styles & Layout - オリジナリティと温かみ */
html, body {
height: 100%;
margin: 0;
padding: 0;
/* 手書き風フォントを優先し、なければ読みやすいゴシック体へ */
font-family: 'Hannotate SC', 'BIZ UDPGothic', 'Yu Gothic', 'Meiryo', sans-serif;
color: #4A4A4A; /* 少し柔らかい黒 */
background-color: #FDF9F3; /* 羊皮紙のようなクリーム系の背景 */
line-height: 1.7; /* ゆったりとした行間 */
letter-spacing: 0.03em; /* 全体的に文字間を少し開ける */
}
#container {
display: flex;
height: 100vh;
width: 100vw;
overflow: hidden;
}
/* Sidebar Styles - 手作りの木製フレーム風 */
#sidebar {
width: 380px; /* ゆったりとした幅 */
flex-shrink: 0;
background-color: #EDEBE0; /* 明るい木目調の背景色 */
padding: 35px; /* さらに広いパディング */
overflow-y: auto;
border-right: 5px solid #C2B280; /* 太めの木材風ボーダー */
box-shadow: 6px 0 15px rgba(0, 0, 0, 0.15); /* 深みのある影 */
z-index: 1000;
transition: width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); /* なめらかなアニメーション */
display: flex;
flex-direction: column;
position: relative; /* 装飾用 */
}
/* サイドバーの角にさりげない装飾 */
#sidebar::before, #sidebar::after {
content: '';
position: absolute;
background-color: #D4CDAE; /* アクセントカラー */
width: 20px;
height: 20px;
border-radius: 50%;
opacity: 0.7;
}
#sidebar::before {
top: 15px;
left: 15px;
}
#sidebar::after {
bottom: 15px;
right: 15px;
}
#sidebar h2 {
margin-top: 0;
margin-bottom: 40px;
color: #5A6F4E; /* 森のような深い緑 */
font-size: 2.5em; /* 存在感のあるタイトル */
/* 手書き感を出すためのボーダーとパディング */
border-bottom: 4px dashed #8F9E7D;
padding-bottom: 15px;
text-align: center;
letter-spacing: 0.08em;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1); /* ほんのり影をつけて立体感 */
}
#comments-list {
flex-grow: 1;
margin-top: 25px;
padding-right: 10px;
}
/* Map Styles */
#map {
flex-grow: 1;
height: 100vh;
z-index: 0;
background-color: #E0E0E0; /* 地図のデフォルト背景 */
border-left: 1px solid #ddd; /* サイドバーとの境界を明確に */
}
/* History Entry Styles - 古い日記帳のページ風 */
.history-entry {
background-color: #FCFCF5; /* 白に近いクリーム色 */
border: 3px solid #D4CDAE; /* 手で描いたような太めのボーダー */
border-radius: 12px;
padding: 22px;
margin-bottom: 25px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease-in-out;
position: relative;
/* 少し傾けて手帳感を出す */
transform: rotate(calc(var(--rotation) * 1deg));
--rotation: 0; /* JavaScriptでランダムな角度を設定するため初期値は0 */
}
.history-entry:hover {
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
transform: translateY(-4px) scale(1.01) rotate(0deg); /* ホバーでまっすぐに、少し拡大 */
}
.history-entry p {
margin: 10px 0;
font-size: 1.15em; /* 大きめのフォント */
color: #555555;
line-height: 1.7;
}
.history-entry p strong {
color: #6B8E23; /* 落ち着いたオリーブグリーン */
font-weight: bold; /* 強調を明確に */
border-bottom: 1px dotted #A0C080; /* 点線でさりげない下線 */
padding-bottom: 2px;
}
/* Editable Comment Text - 手書きノート風 */
.comment-text[contenteditable="true"] {
border: 2px dashed #B8D8BA; /* 手書きのような点線ボーダー */
border-radius: 8px;
padding: 12px;
background-color: #FDFDF8; /* やや黄みがかった白 */
display: block;
width: calc(100% - 24px);
box-sizing: border-box;
font-size: 1.1em;
line-height: 1.6;
min-height: 100px; /* 余裕のある高さ */
overflow: auto;
word-wrap: break-word;
box-shadow: inset 1px 1px 3px rgba(0,0,0,0.05); /* 内側にわずかな影 */
}
.comment-text[contenteditable="true"]:focus {
outline: 4px solid #82B366; /* 目を引く鮮やかな緑の枠線 */
border-color: #82B366;
box-shadow: 0 0 8px rgba(130, 179, 102, 0.5);
}
/* Delete Button in History Entry - 葉っぱのアイコン風 */
.history-entry button {
background-color: #A0522D; /* 土のような落ち着いた茶色 */
color: #FFFFFF;
border: none;
padding: 10px 18px; /* 大きく、押しやすく */
border-radius: 20px; /* 楕円形に近く、葉っぱのような形 */
cursor: pointer;
font-size: 1em;
position: absolute;
top: 18px;
right: 18px;
transition: background-color 0.3s ease, transform 0.2s ease, opacity 0.3s ease;
opacity: 0;
visibility: hidden;
box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
font-weight: bold;
}
.history-entry:hover button {
opacity: 1;
visibility: visible;
transform: scale(1.05); /* 少し拡大 */
}
.history-entry button:hover {
background-color: #8B4513; /* 深い茶色に変化 */
transform: scale(1.1) rotate(2deg); /* さらなる拡大とわずかな回転 */
}
/* Leaflet Popup Overrides - やや厚みのあるカード風 */
.leaflet-popup-content-wrapper {
background: #FFFFFF;
border-radius: 18px;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25); /* 強い影で存在感 */
padding: 0;
border: 2px solid #D4CDAE; /* ページのようなボーダー */
}
.leaflet-popup-content {
margin: 25px 30px 25px 30px;
width: 600px !important; /* 広めのポップアップ */
max-width: none !important;
font-size: 1.2em;
color: #444444;
line-height: 1.6;
}
.leaflet-popup-content p {
margin-top: 0;
margin-bottom: 15px;
}
.leaflet-popup-content p:last-child {
margin-bottom: 0;
}
.leaflet-popup-content textarea,
.comment-input {
width: calc(100% - 20px);
height: 140px; /* 十分な高さ */
font-size: 1.1rem;
padding: 10px;
box-sizing: border-box;
border-radius: 10px;
border: 2px solid #B0C4DE; /* やわらかい青系のボーダー */
resize: vertical;
transition: border-color 0.3s ease;
box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}
.leaflet-popup-content textarea:focus,
.comment-input:focus {
border-color: #7DB9E8; /* 空を思わせる青で強調 */
outline: none;
box-shadow: 0 0 10px rgba(125, 185, 232, 0.6);
}
.leaflet-popup-content button {
margin-top: 25px;
width: 100%;
padding: 18px;
font-size: 1.25rem; /* ボタンの文字を大きく */
background-color: #82B366; /* 自然な緑色 */
color: white;
border: none;
cursor: pointer;
border-radius: 10px;
transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
box-shadow: 0 4px 10px rgba(0,0,0,0.2); /* ボタンにも影 */
font-weight: bold;
}
.leaflet-popup-content button:hover {
background-color: #6A995C; /* 深い緑に変化 */
transform: translateY(-3px); /* 大きく浮き上がる */
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
.leaflet-popup-tip {
background: #FFFFFF;
box-shadow: 0 8px 30px rgba(0,0,0,0.25);
border: 2px solid #D4CDAE; /* ポップアップ本体とボーダーを合わせる */
}
</style>
</head>
<body>
<div id="container">
<div id="sidebar">
<h2>いきいきMAP 活動履歴</h2>
<div id="comments-list"></div>
</div>
<div id="map"></div>
</div>
<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>
<script>
// 地図の初期化 (山形県酒田市の中心に近い座標)
const map = L.map('map').setView([38.9122, 139.8360], 13);
const firebaseConfig = {
apiKey: "ここにYOUR_API_KEYを貼り付ける", // 例: "AIzaSy..."
authDomain: "ここにYOUR_AUTH_DOMAINを貼り付ける", // 例: "your-project-id.firebaseapp.com"
projectId: "ここにYOUR_PROJECT_IDを貼り付ける", // 例: "your-project-id"
storageBucket: "ここにYOUR_STORAGE_BUCKETを貼り付ける",
messagingSenderId: "ここにYOUR_MESSAGING_SENDER_IDを貼り付ける",
appId: "ここにYOUR_APP_IDを貼り付ける"
};
// 国土地理院の地図タイルレイヤーを追加
L.tileLayer('https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', {
attribution: '<a href="https://maps.gsi.go.jp/development/ichiran.html">国土地理院</a>',
maxZoom: 18,
minZoom: 5
}).addTo(map);
// ページ読み込み時の処理
window.addEventListener('load', () => {
// 保存されたコメントとマーカーをロード
loadSavedComments();
// マップのリサイズを強制 (表示崩れ対策)
setTimeout(() => {
map.invalidateSize();
}, 100);
});
// マーカーを管理する配列。この配列のインデックスとローカルストレージのデータのインデックスを同期させる
let markers = [];
// 地図をクリックしてマーカーと情報ウィンドウを追加
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 = `
<div class="info-window">
<p>活動日記を入力してください:</p>
<textarea id="comment" rows="3" style="width:100%;"></textarea>
<button onclick="saveComment('${lat}', '${lng}')">保存</button>
</div>
`;
marker.bindPopup(popupContent).openPopup();
}
// コメントを保存し、履歴に追加
function saveComment(lat, lng) {
const comment = document.getElementById("comment").value;
const timestamp = new Date().toLocaleString();
if (!comment.trim()) {
alert("コメントを入力してください。");
return;
}
const entry = { lat, lng, comment, timestamp };
saveToLocalStorage(entry); // ローカルストレージに保存
// 保存後、すべてのコメントとマーカーを再ロードしてUIを更新
reloadComments();
}
// ローカルストレージにコメントを保存
function saveToLocalStorage(entry) {
let comments = JSON.parse(localStorage.getItem('comments')) || [];
comments.push(entry);
localStorage.setItem('comments', JSON.stringify(comments));
}
// 保存されたコメントをロードして表示し、対応するマーカーも作成
function loadSavedComments() {
const comments = JSON.parse(localStorage.getItem('comments')) || [];
// 古いマーカーをすべて地図から削除し、markers配列をリセット
markers.forEach(marker => map.removeLayer(marker));
markers = [];
// コメント履歴リストをクリア
document.getElementById("comments-list").innerHTML = "";
// 新しいコメントとマーカーを再構築
comments.forEach((entry, index) => {
// サイドバーにコメントを追加
addCommentToHistory(entry, index);
// 地図にマーカーを追加
const marker = L.marker([entry.lat, entry.lng]).addTo(map);
// markers配列にマーカーを追加。これで配列のインデックスがローカルストレージのデータと同期する
markers.push(marker);
// マーカーのポップアップ内容を設定
marker.bindPopup(`
<div class="info-window">
<p><strong>日時:</strong> ${entry.timestamp}</p>
<p><strong>コメント:</strong> ${entry.comment}</p>
</div>
`);
});
// コメントエントリにランダムな回転を適用(デザイン用)
document.querySelectorAll('.history-entry').forEach((el) => {
const rotation = (Math.random() * 2 - 1).toFixed(1); /* -1.0から1.0までのランダムな角度 */
el.style.setProperty('--rotation', rotation);
});
}
// 履歴にコメント要素を動的に追加
function addCommentToHistory({ lat, lng, comment, timestamp }, index) {
const commentsList = document.getElementById("comments-list");
const commentEntryDiv = document.createElement('div');
commentEntryDiv.className = "history-entry";
// ローカルストレージのインデックスと一致するようにdata-index属性を設定
commentEntryDiv.setAttribute('data-index', index);
commentEntryDiv.innerHTML = `
<p><strong>日時:</strong> ${timestamp}</p>
<p><strong>場所:</strong> 緯度 ${lat}, 経度 ${lng}</p>
<p><strong>活動日記:</strong>
<span class="comment-text" contenteditable="true" onblur="updateComment(${index}, this)">
${comment}
</span>
</p>
<button onclick="deleteComment(${index})">削除</button>
`;
commentsList.appendChild(commentEntryDiv);
}
// コメントを削除(対応するマーカーも同時に削除されるように修正)
function deleteComment(index) {
let comments = JSON.parse(localStorage.getItem('comments')) || [];
// 地図上の該当マーカーを削除
if (markers[index]) {
map.removeLayer(markers[index]);
markers.splice(index, 1); // markers配列からも削除
}
// ローカルストレージからコメントを削除
comments.splice(index, 1);
localStorage.setItem('comments', JSON.stringify(comments));
// コメントとマーカーの再同期
reloadComments();
}
// コメントを直接編集し保存する
function updateComment(index, element) {
let comments = JSON.parse(localStorage.getItem('comments')) || [];
const newComment = element.textContent.trim();
if (!newComment) {
alert("コメントは空白にできません。元の内容に戻します。");
element.textContent = comments[index].comment;
return;
}
// コメントを更新してローカルストレージに保存
comments[index].comment = newComment;
localStorage.setItem('comments', JSON.stringify(comments));
// 変更を反映させるため、UI全体を再ロードして同期させる
reloadComments();
}
// コメント履歴とマーカーを完全にリロードして同期させる関数
function reloadComments() {
// loadSavedComments関数が、履歴リストのクリア、マーカーの削除とリセット、そして再描画をすべて行う
loadSavedComments();
}
</script>
</body>
</html>