-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalerts.html
More file actions
211 lines (194 loc) · 7.31 KB
/
Copy pathalerts.html
File metadata and controls
211 lines (194 loc) · 7.31 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hurricane Alerts - Weather</title>
<style>
body {
font-family: sans-serif;
margin: 0;
background-size: cover;
color: white;
}
.overlay-image {
width: 100vw;
height: 100vh;
position: relative;
}
.container {
display: flex; /* Use flexbox */
justify-content: space-between; /* Space between alerts and weather */
padding: 2rem;
background: rgba(0, 0, 0, 0.5);
border-radius: 10px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80%; /* Set a width for the container */
}
.alerts {
color: red;
flex: 1; /* Take up one part of the space */
margin-right: 2rem; /* Space between alerts and conditions */
}
.weather-info {
flex: 1; /* Take up one part of the space */
color: yellow;
}
.report-button {
display: flex;
justify-content: center;
margin-top: 1rem;
}
button.report {
background: #FF0000;
color: white;
padding: 0.4rem 1rem;
border: none;
border-radius: 100px;
width: 134px;
cursor: pointer;
}
button.report:hover {
background: #d4a113;
}
header {
background: #007bff;
color: white;
padding: 1rem;
display: flex;
align-items: center;
justify-content: space-between;
}
nav {
background: white;
padding: 0.5rem;
border-radius: 5px;
margin-top: 0.5rem;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 2000;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
border-bottom: 1px solid #000000;
border: 1px solid #000;
}
p {
font-size: 19px;
}
a {
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<header>
<nav>
<div class="dropdown">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Hamburger_icon.svg/640px-Hamburger_icon.svg.png" alt="Menu" style="width: 30px; cursor: pointer;" />
<div class="dropdown-content">
<a href="alerts.html">Alerts</a>
<a href="educational_content.html">Educational Content</a>
<a href="report_damage.html">Report Damage</a>
<a href="provide_feedback.html">Provide Feedback</a>
<a href="view_feedback.html">View User Submitted Feedback</a>
<a href="view_reports.html">View User Submitted Reports</a>
</div>
</div>
</nav>
<h1 style="margin: 0"><a href="index.html">Disaster Alert System</a></h1>
</header>
<img class="overlay-image" src="https://github.com/Slick9000/crisiswatch.github.io/blob/main/backgroundimg.jpg?raw=true" alt="Hurricane">
<div class="container">
<div class="alerts" id="weather-alerts">
<h1 class="alerts">Alerts</h1>
<div id="alerts-data"></div>
</div>
<div class="weather-info">
<h1 class="current" id="location-name"></h1>
<div id="weather-data"></div>
<div class="report-button">
<a href="report_damage.html">
<button style="color: #000;" class="report"><b>Report Damage</b></button>
</a>
</div>
</div>
</div>
<script>
const urlParams = new URLSearchParams(window.location.search);
var lat = urlParams.get('lat');
var lon = urlParams.get('lon');
if (lat && lon) {
localStorage.setItem('lat', lat);
localStorage.setItem('lon', lon);
fetchWeather();
} else {
var lat = localStorage.getItem('lat');
var lon = localStorage.getItem('lon');
if (!lat && !lon) {
alert("No initial location selected. Please access the map to select a parish.");
}
}
async function fetchWeather() {
const API_KEY = "6a37f992dfd748d5a2240721250404";
try {
const currentRes = await fetch(`https://api.weatherapi.com/v1/current.json?key=${API_KEY}&q=${lat},${lon}`);
const currentConditions = await currentRes.json();
const forecastRes = await fetch(`https://api.weatherapi.com/v1/forecast.json?key=${API_KEY}&q=${lat},${lon}&days=1`);
const forecastData = await forecastRes.json();
const alertsRes = await fetch(`https://api.weatherapi.com/v1/alerts.json?key=${API_KEY}&q=${lat},${lon}`);
const alerts = await alertsRes.json();
displayWeather(currentConditions, forecastData.forecast.forecastday, alerts);
} catch (error) {
alert("Error fetching weather data.");
console.log(error);
}
}
function displayWeather(currentConditions, forecastDays, alerts) {
const weatherContainer = document.getElementById("weather-data");
let html = `<h1 class="current">Current Conditions</h1>`;
if (currentConditions) {
const location = currentConditions.location;
const current = currentConditions.current;
const selected_location = `${location.region}\n${location.country}`;
document.getElementById("location-name").innerText = selected_location;
html += `<p class="current">${current.condition.text} - ${current.temp_c}°C</p>`;
} else {
html += `<p class="current">No current conditions available.</p>`;
}
html += `<h1 class="current">Forecast</h1>`;
forecastDays.forEach((day) => {
html += `<p class="current">${day.date}: Max ${day.day.maxtemp_c}°C, Min ${day.day.mintemp_c}°C - ${day.day.condition.text}</p>`;
});
weatherContainer.innerHTML = html;
const alertsContainer = document.getElementById("alerts-data");
if (alerts && alerts.alert) {
alerts.alert.forEach((alert) => {
alertsContainer.innerHTML += `<p class="alerts"><strong>${alert.headline}</strong>: ${alert.desc}</p>`;
});
} else {
alertsContainer.innerHTML = `<p class="alerts">No current alerts.</p>`;
}
}
fetchWeather();
</script>
</body>
</html>