-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
128 lines (106 loc) · 4.3 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
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
function initMap() {
const map = L.map('map').setView([28.5383, -81.3792], 10); // Orlando, FL
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
const floodedZones = [
{ lat: 28.5383, lng: -81.3792, title: 'Zone 1: Accessible' },
{ lat: 28.5500, lng: -81.4000, title: 'Zone 2: Limited Access' },
{ lat: 28.5400, lng: -81.3700, title: 'Zone 3: No Access' },
{ lat: 28.5450, lng: -81.3750, title: 'Zone 4: Accessible' },
{ lat: 28.5300, lng: -81.3950, title: 'Zone 5: Limited Access' },
{ lat: 28.5250, lng: -81.3850, title: 'Zone 6: No Access' }
];
floodedZones.forEach(zone => {
L.marker([zone.lat, zone.lng]).addTo(map).bindPopup(zone.title);
});
const geocoder = L.Control.geocoder({
defaultMarkGeocode: false
})
.on('markgeocode', function(e) {
const latlng = e.geocode.center;
const marker = L.marker(latlng).addTo(map);
map.setView(latlng, 16);
marker.bindPopup(e.geocode.name).openPopup();
// Check if the searched location is within a flooded zone
let inFloodZone = false;
floodedZones.forEach(zone => {
const distance = map.distance(latlng, L.latLng(zone.lat, zone.lng));
if (distance < 500) { // Assuming a 500-meter radius for simplicity
inFloodZone = true;
alert(`Warning: You are in a flooded zone - ${zone.title}`);
}
});
if (!inFloodZone) {
alert('You are not in a flooded zone.');
}
})
.addTo(map);
// Event listeners for checkboxes
document.getElementById('disability').addEventListener('change', function() {
document.getElementById('disabilityCount').disabled = !this.checked;
});
document.getElementById('children').addEventListener('change', function() {
document.getElementById('childrenCount').disabled = !this.checked;
});
document.getElementById('pets').addEventListener('change', function() {
document.getElementById('petsCount').disabled = !this.checked;
});
document.getElementById('elders').addEventListener('change', function() {
document.getElementById('eldersCount').disabled = !this.checked;
});
}
function submitUserInfo() {
const disability = document.getElementById('disability').checked;
const disabilityCount = document.getElementById('disabilityCount').value || 0;
const children = document.getElementById('children').checked;
const childrenCount = document.getElementById('childrenCount').value || 0;
const pets = document.getElementById('pets').checked;
const petsCount = document.getElementById('petsCount').value || 0;
const elders = document.getElementById('elders').checked;
const eldersCount = document.getElementById('eldersCount').value || 0;
const evacuationRoutes = document.getElementById('evacuationRoutes').checked;
alert(`User Info:
Disability: ${disability} (${disabilityCount})
Children: ${children} (${childrenCount})
Pets: ${pets} (${petsCount})
Elders: ${elders} (${eldersCount})
Need Evacuation Routes: ${evacuationRoutes}`);
if (evacuationRoutes) {
displayEvacuationRoutes();
}
}
function displayEvacuationRoutes() {
const map = L.map('map').setView([28.5383, -81.3792], 10); // Ensure map instance
const evacuationRoutes = [
// Connect each flooded zone to a safe zone (example coordinates)
[
[28.5383, -81.3792], // Zone 1
[28.6000, -81.4000] // Safe Zone
],
[
[28.5500, -81.4000], // Zone 2
[28.6000, -81.4000] // Safe Zone
],
[
[28.5400, -81.3700], // Zone 3
[28.6000, -81.4000] // Safe Zone
],
[
[28.5450, -81.3750], // Zone 4
[28.6000, -81.4000] // Safe Zone
],
[
[28.5300, -81.3950], // Zone 5
[28.6000, -81.4000] // Safe Zone
],
[
[28.5250, -81.3850], // Zone 6
[28.6000, -81.4000] // Safe Zone
]
];
evacuationRoutes.forEach(route => {
L.polyline(route, { color: 'blue' }).addTo(map);
});
}
document.addEventListener('DOMContentLoaded', initMap);