-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
71 lines (59 loc) · 2.35 KB
/
script.js
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
document.getElementById('fire-report-form').addEventListener('submit', async function(event) {
event.preventDefault();
const description = document.getElementById('fire-report-form').value;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(async function(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const response = await fetch('http://127.0.0.1:8000/twilio_redirect', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
location: { latitude, longitude },
description // inclui descrição
})
});
const result = await response.json();
alert(result.message);
}, function(error) {
alert('Erro ao obter localização: ' + error.message);
});
} else {
alert('Geolocalização não é suportada pelo seu navegador.');
}
});
document.getElementById('anonymous-report-form').addEventListener('submit', async function(event) {
event.preventDefault();
const description = document.getElementById('anon-description').value;
const state = document.getElementById('state').value;
const response = await fetch('http://127.0.0.1:8000/anonymous_report', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
description,
state
})
});
const result = await response.json();
alert(result.message);
});
// Inicializar o map
const map = L.map('map').setView([-14.2350, -51.9253], 4);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> Contributors',
maxZoom: 18,
}).addTo(map);
// Obter pontos de incêndio do servidor
async function getFirePoints() {
const response = await fetch('http://127.0.0.1:8000/fire_points');
const firePoints = await response.json();
firePoints.forEach(point => {
L.marker([point.latitude, point.longitude]).addTo(map)
.bindPopup(`Incêndio relatado: ${point.latitude}, ${point.longitude}`);
});
}
getFirePoints();