forked from mike-cautela/MunchiMaps
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
557 lines (466 loc) · 22.5 KB
/
Copy pathscript.js
File metadata and controls
557 lines (466 loc) · 22.5 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
//initializes the map
function initMap() {
const map = L.map('map').setView([42.72941085967446, -73.6792590320996], 17);
var currentMarker = null; // Variable to keep track of the current marker
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
detectRetina: true,
maxZoom: 50
}).addTo(map);
var locationDot = L.divIcon({
className: 'custom-icon',
html: '<div class="location-circle"></div><div class="location-dot"></div>',
iconSize: [40, 40],
iconAnchor: [1, 3] // Center the icon
});
// Function to handle location found
function onLocationFound(e) {
console.log("Location found: ", e.latlng);
// Remove the old marker if it exists
if (currentMarker) {
map.removeLayer(currentMarker);
}
// Add a new marker
currentMarker = L.marker(e.latlng, {icon: locationDot}).addTo(map).bindPopup("You are here").openPopup();
map.setView(e.latlng, 18); // Center the map on the user's location
}
// Function to handle location errors
function onLocationError(e) {
console.log("Location error: ", e.message);
alert(e.message);
}
// Initial location finding
map.locate({
setView: true,
maxZoom: 18,
watch: false
}).on('locationfound', onLocationFound).on('locationerror', onLocationError);
// Define the centerMap function
function centerMap(){
map.locate({
setView: true,
maxZoom: 18,
watch: false
}).on('locationfound', onLocationFound).on('locationerror', onLocationError);
}
var button = document.getElementById("Location");
if (button) {
console.log("Button found, adding event listener");
button.addEventListener("click", centerMap);
} else {
console.log("Button not found");
}
//Puts the zoom in bottom left corner
map.zoomControl.setPosition('bottomleft');
//Gets the icon for vending machines available from github.
const foodanddrink = L.icon({
iconUrl: 'https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/Food&Drink.png?raw=true',
iconSize: [80, 50],
iconAnchor: [50, 25]
});
const food = L.icon({
iconUrl: 'https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/Food.png?raw=true',
iconSize: [50, 50],
iconAnchor: [50, 25]
});
const drink = L.icon({
iconUrl: 'https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/Drink.png?raw=true',
iconSize: [50, 50],
iconAnchor: [50, 25]
});
//Marker locations.
const folsom = L.marker([42.7294361078206, -73.68252684056829], { icon: foodanddrink }).addTo(map);
const jrowl = L.marker([42.7288, -73.6804], { icon: foodanddrink }).addTo(map);
const eaton = L.marker([42.730310, -73.682501], { icon: drink}).addTo(map);
const greene = L.marker([42.730136, -73.681213], { icon: foodanddrink }).addTo(map);
const academy = L.marker([42.727497, -73.678723], { icon: foodanddrink }).addTo(map);
//generating the description based on image that it is given
function generatedescription(image1, image2, image3) {
let results = ["This vending machine accepts: "];
if (image1 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditCheck.png?raw=true") {
results.push("card");
} else if (image1 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditX.png?raw=true") {
results.push("");
}
if (image2 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashCheck.png?raw=true") {
if (image1 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditX.png?raw=true") {
results.push("cash");
} else {
results.push(", cash");
}
} else if (image2 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashX.png?raw=true") {
results.push("");
}
if (image3 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneCheck.png?raw=true") {
if (image1 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditX.png?raw=true" && image2 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashX.png?raw=true") {
results.push("wireless payments");
} else {
results.push(", wireless payments");
}
} else if (image3 === "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneX.png?raw=true.png") {
results.push("");
}
return results.join("");
}
//Contains all images for Folsom + icons
// Variable containing the dynamic content
const image1 = "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditCheck.png?raw=true";
const image2 = "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashCheck.png?raw=true";
const image3 = "https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneX.png?raw=true";
const description = generatedescription(image1, image2, image3);
// Info window content using template literal
const infoWindowContent = `
<div class="info-window-content">
<div class="info-window-image">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Folsom/FolsomDrink1.jpg?raw=true" alt="Logo 1" class="active">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Folsom/FolsomDrink2.jpg?raw=true" alt="Logo 2">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Folsom/FolsomFood1.jpg?raw=true" alt="Logo 3">
<div class="carousel-controls">
<button class="prev"><</button>
<button class="next">></button>
</div>
</div>
<div class="info-window-text">
<div class="info-window-title">Folsom Library</div>
<div class="info-window-icons">
<img src="${image1}">
<img src="${image2}" alt="Image 2">
<img src="${image3}" alt="Image 3">
</div>
<div class="info-window-subtitle">${description}</div>
</div>
</div>`;
//Function to open the info window at Folsom Location
folsom.on('click', function () {
const infoWindow = L.popup({maxWidth: 500})
.setLatLng([42.7294361078206, -73.68252684056829])
.setContent(infoWindowContent)
.openOn(map);
//Handles image selector for Folsom Location
const images = document.querySelectorAll('.info-window-image img');
const prevButton = document.querySelector('.prev');
const nextButton = document.querySelector('.next');
let currentIndex = 0;
function showImage(index) {
images.forEach((img, i) => {
img.classList.toggle('active', i === index);
});
}
prevButton.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : images.length - 1;
showImage(currentIndex);
});
nextButton.addEventListener('click', () => {
currentIndex = (currentIndex < images.length - 1) ? currentIndex + 1 : 0;
showImage(currentIndex);
});
});
const jrowl_info = `
<div class="info-window-content">
<div class="info-window-image">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/JROWL/JROWLDrink.jpg?raw=true" alt="Logo 1" class="active">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/JROWL/JROWLSnack.jpg?raw=true" alt="Logo 2">
<div class="carousel-controls">
<button class="prev"><</button>
<button class="next">></button>
</div>
</div>
<div class="info-window-text">
<div class="info-window-title">JROWL</div>
<div class="info-window-icons">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditCheck.png?raw=true">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashCheck.png?raw=true" alt="Image 2">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneX.png?raw=true" alt="Image 3">
</div>
<div class="info-window-subtitle">This machine accepts cash and credit cards.</div>
</div>
</div>
`;
jrowl.on('click', function () {
const infoWindow = L.popup({maxWidth: 500})
.setLatLng([42.7288, -73.6804])
.setContent(jrowl_info)
.openOn(map);
const images = document.querySelectorAll('.info-window-image img');
const prevButton = document.querySelector('.prev');
const nextButton = document.querySelector('.next');
let currentIndex = 0;
function showImage(index) {
images.forEach((img, i) => {
img.classList.toggle('active', i === index);
});
}
prevButton.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : images.length - 1;
showImage(currentIndex);
});
nextButton.addEventListener('click', () => {
currentIndex = (currentIndex < images.length - 1) ? currentIndex + 1 : 0;
showImage(currentIndex);
});
});
const eaton_info = `
<div class="info-window-content">
<div class="info-window-image">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Amos%20Eaton/AmosEatonDrink.jpg?raw=true" alt="Logo 1" class="active">
<div class="carousel-controls">
<button class="prev"><</button>
<button class="next">></button>
</div>
</div>
<div class="info-window-text">
<div class="info-window-title">Amos Eaton</div>
<div class="info-window-icons">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditCheck.png?raw=true">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashCheck.png?raw=true" alt="Image 2">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneX.png?raw=true" alt="Image 3">
</div>
<div class="info-window-subtitle">This machine accepts cash and credit cards.</div>
</div>
</div>
`;
eaton.on('click', function () {
const infoWindow = L.popup({maxWidth: 500})
.setLatLng([42.730310, -73.682501])
.setContent(eaton_info)
.openOn(map);
const images = document.querySelectorAll('.info-window-image img');
const prevButton = document.querySelector('.prev');
const nextButton = document.querySelector('.next');
let currentIndex = 0;
function showImage(index) {
images.forEach((img, i) => {
img.classList.toggle('active', i === index);
});
}
prevButton.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : images.length - 1;
showImage(currentIndex);
});
nextButton.addEventListener('click', () => {
currentIndex = (currentIndex < images.length - 1) ? currentIndex + 1 : 0;
showImage(currentIndex);
});
});
const greene_info = `
<div class="info-window-content">
<div class="info-window-image">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Greene/GreeneDrink.jpg?raw=true" alt="Logo 1" class="active">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Greene/GreeneSnack.jpg?raw=true" alt="Logo 2">
<div class="carousel-controls">
<button class="prev"><</button>
<button class="next">></button>
</div>
</div>
<div class="info-window-text">
<div class="info-window-title">Greene Building</div>
<div class="info-window-icons">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditCheck.png?raw=true">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashCheck.png?raw=true" alt="Image 2">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneX.png?raw=true" alt="Image 3">
</div>
<div class="info-window-subtitle">This machine accepts cash and credit cards.</div>
<!-- Draft review function for the vending machine -->
<div class="review-section">
<div class="reviews">
<!-- Existing reviews will be appended here -->
</div>
<h4>Write a Review</h4>
<textarea id="review-text" placeholder="Write your review here..." required></textarea>
<div class="rating">
<span rating-star="5">★</span>
<span rating-star="4">★</span>
<span rating-star="3">★</span>
<span rating-star="2">★</span>
<span rating-star="1">★</span>
</div>
<button type="submit">Submit</button>
<form class="submit-review">
</form>
</div>
</div>
</div>
`;
greene.on('click', function () {
const infoWindow = L.popup({maxWidth: 500})
.setLatLng([42.730136, -73.681213])
.setContent(greene_info)
.openOn(map);
const images = document.querySelectorAll('.info-window-image img');
const prevButton = document.querySelector('.prev');
const nextButton = document.querySelector('.next');
let currentIndex = 0;
function showImage(index) {
images.forEach((img, i) => {
img.classList.toggle('active', i === index);
});
}
prevButton.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : images.length - 1;
showImage(currentIndex);
});
nextButton.addEventListener('click', () => {
currentIndex = (currentIndex < images.length - 1) ? currentIndex + 1 : 0;
showImage(currentIndex);
});
//review section javascript
const submitReview = document.querySelector('.submit-review');
const reviewsContainer = document.querySelector('.reviews');
reviewForm.addEventListener('submit', (event) => {
event.preventDefault();
const reviewText = document.getElementById('review-text').value;
const rating = document.getElementById('rating').value;
// Append new review to the reviews container
const reviewElement = document.createElement('div');
reviewElement.classList.add('review');
reviewElement.innerHTML = `
<p>${reviewText}</p>
<p>Rating: ${'★'.repeat(rating)}${'☆'.repeat(5 - rating)}</p>
`;
reviewsContainer.appendChild(reviewElement);
// Clear the form
reviewForm.reset();
});
});
const academy_info = `
<div class="info-window-content">
<div class="info-window-image">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Academy%20Hall/AcademyHallDrink.jpg?raw=true" alt="Logo 1" class="active">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Academy%20Hall/AcademyHallSnack.jpg?raw=true" alt="Logo 2">
<div class="carousel-controls">
<button class="prev"><</button>
<button class="next">></button>
</div>
</div>
<div class="info-window-text">
<div class="info-window-title">Academy Hall</div>
<div class="info-window-icons">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CreditCheck.png?raw=true">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/CashCheck.png?raw=true" alt="Image 2">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneX.png?raw=true" alt="Image 3">
<img src="https://github.com/mike-cautela/MunchiMaps/blob/main/MunchiMaps%20Assets/Map%20Icons/PhoneCheck.png?raw=true" alt="Image 4">
</div>
<div class="info-window-subtitle">These machines accept cash and credit cards. The beverage machine also accepts tap to pay.</div>
</div>
</div>
`;
academy.on('click', function () {
const infoWindow = L.popup({maxWidth: 500})
.setLatLng([42.727497, -73.678723])
.setContent(academy_info)
.openOn(map);
const images = document.querySelectorAll('.info-window-image img');
const prevButton = document.querySelector('.prev');
const nextButton = document.querySelector('.next');
let currentIndex = 0;
function showImage(index) {
images.forEach((img, i) => {
img.classList.toggle('active', i === index);
});
}
prevButton.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : images.length - 1;
showImage(currentIndex);
});
nextButton.addEventListener('click', () => {
currentIndex = (currentIndex < images.length - 1) ? currentIndex + 1 : 0;
showImage(currentIndex);
});
});
/* OBSOLETE IGNORE
//Dark mode code.
let darkMode = false;
function toggleDarkMode() {
darkMode = !darkMode;
const logotitle = document.querySelector('.logo-title');
const button = document.querySelector('.button');
const help = document.querySelector('.help-button-img');
if (darkMode) {
document.body.classList.add('dark-mode');
logotitle.classList.add('dark-mode');
button.classList.add('dark-mode');
help.classList.add('dark-mode');
} else {
document.body.classList.remove('dark-mode');
logotitle.classList.remove('dark-mode');
button.classList.remove('dark-mode');
help.classList.remove('dark-mode');
}
}
*/
// Toggle between dark mode and light mode CSS sheets.
let darkMode = false;
function toggleDarkMode() {
darkMode = !darkMode;
const light = document.getElementById('light-mode');
const dark = document.getElementById('dark-mode');
if (darkMode){
dark.disabled = false;
setTimeout(() => {
light.disabled = true;
}, 200); //Delay for smooth transition
} else {
light.disabled = false;
setTimeout(() => {
dark.disabled = true;
}, 200);
}
}
//Toggles dark mode when user presses 'd' or 'D.'
document.addEventListener('keydown', function(event) {
if ((event.key === 'd' || event.key === 'D') &&
(document.activeElement.tagName !== 'INPUT' &&
document.activeElement.tagName !== 'TEXTAREA' &&
document.activeElement.contentEditable !== 'true')){
toggleDarkMode();
}
});
} // init map ending bracket here
function openHelp() {
document.getElementById("help-popup").style.display = "block";
}
function closeHelp() {
document.getElementById("help-popup").style.display = "none";
}
// Close the help popup if the user clicks outside of the help content
window.onclick = function(event) {
const popup = document.getElementById("help-popup");
if (event.target === popup) {
popup.style.display = "none";
}
}
function openPopup(id) {
closeAllPopups();
document.getElementById('popup-' + id.toLowerCase()).style.display = 'block';
}
function closePopup(id) {
document.getElementById('popup-' + id.toLowerCase()).style.display = 'none';
}
//Closes all popups when user clicks on second popup.
function closeAllPopups() {
document.querySelectorAll('.popup-container').forEach((popup) => {
popup.style.display = 'none';
});
}
document.addEventListener('DOMContentLoaded', function () {
initMap();
});
// Handle report form submission
document.addEventListener('DOMContentLoaded', function () {
initMap();
const reportForm = document.getElementById('reportForm');
reportForm.addEventListener('submit', function(event) {
event.preventDefault();
const reportTitle = document.getElementById('reportTitle').value;
const reportDescription = document.getElementById('reportDescription').value;
// Handle the form data (e.g., send it to a server or display it)
console.log('Report Title:', reportTitle);
console.log('Report Description:', reportDescription);
// Display a confirmation message or handle the submission
alert('Report submitted successfully!');
// Close the popup
closePopup('Report');
// Clear the form
reportForm.reset();
});
});