-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
202 lines (172 loc) · 5.3 KB
/
index.html
File metadata and controls
202 lines (172 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>MapMyMemories – Free Version</title>
<!-- Leaflet CSS & JS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<style>
* {
box-sizing: border-box;
}
body, html {
margin: 0;
padding: 0;
height: 100%;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #4e3ba3;
}
#map {
height: 100%;
}
.form-box {
position: fixed;
top: 20px;
left: 20px;
background-color: #544141;
padding: 20px;
width: 280px;
z-index: 999;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.form-box h3 {
margin: 0 0 15px;
font-size: 18px;
color: #333;
}
input[type="text"], textarea, input[type="file"], button {
width: 100%;
padding: 8px 10px;
margin-top: 10px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 6px;
transition: border-color 0.2s;
}
input:focus, textarea:focus {
border-color: #007BFF;
outline: none;
}
textarea {
resize: vertical;
min-height: 60px;
}
button {
background-color: #007BFF;
color: white;
border: none;
font-weight: 600;
cursor: pointer;
margin-top: 15px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
#preview {
margin-top: 12px;
max-width: 100%;
border-radius: 6px;
display: none;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="form-box">
<h3>📍 Add a New Memory</h3>
<input type="file" id="imgInput" accept="image/*" />
<input type="text" id="title" placeholder="Memory Title" />
<textarea id="desc" placeholder="Memory Description"></textarea>
<button onclick="addMemory()">Pin to Map</button>
<img id="preview" alt="Image Preview" />
</div>
<div id="map"></div>
<script>
const imgbbAPIKey = "ef72e9462a0a02572688a4c3657212d5"; // 🔑 Replace with your ImgBB key
let selectedCoords = null;
let imageFile = null;
const map = L.map('map').setView([20.5937, 78.9629], 5);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
map.on("click", function (e) {
selectedCoords = e.latlng;
alert("📍 Location selected!");
});
document.getElementById("imgInput").addEventListener("change", function () {
imageFile = this.files[0];
if (imageFile) {
const reader = new FileReader();
reader.onload = function (e) {
const preview = document.getElementById("preview");
preview.src = e.target.result;
preview.style.display = "block";
};
reader.readAsDataURL(imageFile);
}
});
async function addMemory() {
if (!selectedCoords || !imageFile) {
alert("Please select a location on the map and upload an image.");
return;
}
const title = document.getElementById("title").value.trim();
const desc = document.getElementById("desc").value.trim();
if (!title || !desc) {
alert("Please fill in both title and description.");
return;
}
try {
const formData = new FormData();
formData.append("image", imageFile);
const res = await fetch(`https://api.imgbb.com/1/upload?key=${imgbbAPIKey}`, {
method: "POST",
body: formData
});
const data = await res.json();
if (!data.success) throw new Error("Image upload failed");
const memory = {
title,
desc,
image: data.data.url,
lat: selectedCoords.lat,
lng: selectedCoords.lng,
date: new Date().toISOString()
};
const allMemories = JSON.parse(localStorage.getItem("memories")) || [];
allMemories.push(memory);
localStorage.setItem("memories", JSON.stringify(allMemories));
const marker = L.marker([memory.lat, memory.lng]).addTo(map);
marker.bindPopup(`
<strong>${memory.title}</strong><br>
${memory.desc}<br>
<img src="${memory.image}" style="max-width:200px; border-radius:6px;" />
`);
document.getElementById("title").value = "";
document.getElementById("desc").value = "";
document.getElementById("imgInput").value = "";
document.getElementById("preview").style.display = "none";
selectedCoords = null;
imageFile = null;
alert("✅ Memory pinned successfully!");
} catch (err) {
alert("❌ Error: " + err.message);
}
}
// Load saved memories
const saved = JSON.parse(localStorage.getItem("memories")) || [];
saved.forEach((m) => {
const marker = L.marker([m.lat, m.lng]).addTo(map);
marker.bindPopup(`
<strong>${m.title}</strong><br>
${m.desc}<br>
<img src="${m.image}" style="max-width:200px; border-radius:6px;" />
`);
});
</script>
</body>
</html>