-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapUIHandler.js
More file actions
76 lines (61 loc) · 1.86 KB
/
mapUIHandler.js
File metadata and controls
76 lines (61 loc) · 1.86 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
// import { MapUIHandler } from './mapUIHandler.js';
export class MapUIHandler {
constructor(map) {
this.map = map;
this.setupEventListeners();
}
getImageUploadFormHtml() {
return `
<form id="image-upload-form">
<input type="file" id="image-upload-input" accept="image/*" />
<button type="submit">Upload</button>
</form>
<div id="image-display-area"></div>
`;
}
renderMapMarker(mapset) {
L.marker(mapset.coords)
.addTo(this.map)
.bindPopup(
L.popup({
maxWidth: 250,
minWidth: 100,
autoClose: true,
closeOnClick: true,
className: `${mapset.type}-popup`,
})
)
.setPopupContent(
this.getImageUploadFormHtml() + `${mapset.description}`
)
.on('popupopen', e => {
})
.on('popupclose', e => {
});
}
setupEventListeners() {
document.addEventListener('submit', async function (event) {
if (event.target.matches('#image-upload-form')) {
event.preventDefault();
const fileInput = event.target.querySelector('#image-upload-input');
const file = fileInput.files[0];
if (file) {
try {
const fileUrl = await firebaseStorageUtils.uploadFile(file);
const imageDisplayArea = document.getElementById('image-display-area');
const img = document.createElement('img');
img.src = fileUrl;
imageDisplayArea.appendChild(img);
fileInput.value = '';
alert('Image uploaded successfully!');
} catch (error) {
console.error('Error uploading file:', error);
alert('There was a problem uploading the image.');
}
} else {
alert('Please select a file to upload.');
}
}
});
}
}