-
Notifications
You must be signed in to change notification settings - Fork 0
/
index3.html
499 lines (441 loc) · 17.6 KB
/
index3.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pune District AQI and Weather Monitoring</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<style>
/* Basic styles */
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
margin: 0;
height: 100vh;
overflow: hidden;
}
header, footer {
text-align: center;
color: white;
padding: 10px 0;
font-size: 1rem;
}
header {
background: linear-gradient(135deg, #0099ff, #66ccff);
}
footer {
background: #333;
color: #ccc;
font-size: 0.9rem;
}
#container {
display: flex;
flex: 1;
overflow: hidden;
}
#left-sidebar, #right-sidebar {
width: 18%;
padding: 10px;
background-color: #f7f7f7;
box-shadow: 0 2px 5px rgba(0,0,0,0.3);
overflow-y: auto;
}
#map {
flex: 1;
}
h2, h3 {
margin: 5px 0;
font-size: 1.1rem;
}
p {
margin: 0;
font-size: 0.9rem;
}
/* Styling for the right sidebar */
#right-sidebar {
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px;
font-family: Arial, sans-serif;
color: #333;
line-height: 1.6;
}
/* Styling for each section title */
#right-sidebar h3 {
font-size: 18px;
font-weight: bold;
color: #2c3e50;
margin-bottom: 10px;
border-bottom: 2px solid #ddd;
padding-bottom: 5px;
}
/* Additional spacing between sections */
#right-sidebar .section {
margin-bottom: 20px;
}
/* Styling for the AQI details */
#right-sidebar #aqi-info {
font-size: 16px;
margin-bottom: 10px;
}
/* weather info */
#right-sidebar #weather-info {
font-size: 18px;
margin-bottom: 10px;
}
/* Styling for the legend */
#right-sidebar .legend {
font-size: 14px;
margin-bottom: 20px;
}
/* District list styling */
#left-sidebar ul {
list-style-type: none;
padding: 0;
font-size: 0.9rem;
}
#left-sidebar li {
padding: 6px;
cursor: pointer;
margin-bottom: 2px;
border-radius: 4px;
}
#left-sidebar li:hover {
background-color: #ddd;
}
.selected {
background-color: #b0d4ff;
}
/* Button styling */
#default-zoom-btn {
margin-top: 10px;
padding: 8px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
#default-zoom-btn:hover {
background-color: #0056b3;
}
/* Legend styling */
#legend {
background-color: white;
padding: 10px;
border: 2px solid #ccc;
border-radius: 5px;
margin-top: 10px;
font-size: 0.9rem;
}
.legend-color {
display: inline-block;
width: 20px;
height: 20px;
margin-right: 5px;
border: 1px solid #ccc;
}
.bold-large {
font-weight: bold;
}
.value-large {
font-size: 16px; /* Adjust the font size as needed */
}
/* Style for the layer control icon button */
.leaflet-control-layers-toggle {
width: 30px; /* Increase the width */
height: 30px; /* Increase the height */
background-color: black; /* Set background color to black */
border-radius: 4px; /* Optional: Add rounded corners */
opacity: 0.8; /* Slight transparency */
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); /* Soft shadow for depth */
transition: background-color 0.3s, transform 0.3s; /* Smooth transition effects */
}
/* Adjust the icon image inside the button if necessary */
.leaflet-control-layers-toggle::before {
color: white; /* Set icon color to white for contrast */
font-size: 20px; /* Increase icon size */
}
/* Hover effect for the button */
.leaflet-control-layers-toggle:hover {
background-color: #333; /* Darker shade on hover */
transform: scale(1.1); /* Slight enlargement on hover */
}
/* Style for Leaflet layer control panel */
.leaflet-control-layers-expanded {
font-size: 16px; /* Increase font size */
color: black; /* Set text color to black */
background-color: #f0f0f0; /* Light background for better contrast */
padding: 10px; /* Increase padding for more space */
border-radius: 8px; /* Round the corners */
box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.3); /* Add shadow for depth */
}
/* Style for checkboxes in layer control */
.leaflet-control-layers-list label {
font-weight: bold; /* Make text bold for readability */
color: black; /* Set label text color to black */
}
/* Styling the home button */
.leaflet-bar a {
background-color: #fff;
border-radius: 50%;
border: 2px solid #333;
padding: 5px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.leaflet-bar a:hover {
background-color: #f9f1f1;
}
/* Custom red home button icon */
.home-icon {
display: inline-block;
background-image: url('https://img.icons8.com/?size=100&id=80319&format=png&color=000000');
background-repeat: no-repeat; /* Prevent repeat */
background-position: center; /* Center the icon */
}
.leaflet-bar a:hover .home-icon {
background-color: #ff3939; /* Change the hover color if desired */
}
</style>
</head>
<body>
<header>
<h1>Pune District AQI and Weather Monitoring</h1>
</header>
<div id="container">
<!-- Left sidebar with district list -->
<div id="left-sidebar">
<h2>AQI Map</h2>
<p>Select a Sub-District to view the AQI level.</p>
<ul>
<li onclick="selectDistrict('Pune City', 70)">Pune City (पुणे शहर)</li>
<li onclick="selectDistrict('Baramati', 65)">Baramati (बारामती)</li>
<li onclick="selectDistrict('Junnar', 78)">Junnar (जुन्नर)</li>
<li onclick="selectDistrict('Indapur', 80)">Indapur (इंदापूर)</li>
<li onclick="selectDistrict('Daund', 55)">Daund (दौंड)</li>
<li onclick="selectDistrict('Ambegaon', 90)">Ambegaon (आंबेगाव)</li>
<li onclick="selectDistrict('Khed', 60)">Khed (खेड)</li>
<li onclick="selectDistrict('Shirur', 85)">Shirur (शिरूर)</li>
<li onclick="selectDistrict('Velhe', 40)">Velhe (वेळ्हे)</li>
<li onclick="selectDistrict('Bhor', 75)">Bhor (भोर)</li>
<li onclick="selectDistrict('Mulshi', 67)">Mulshi (मुळशी)</li>
<li onclick="selectDistrict('Maval', 58)">Maval (मावळ)</li>
<li onclick="selectDistrict('Purandar', 85)">Purandar (पुरंदर)</li>
</ul>
<button id="default-zoom-btn" onclick="resetMap()">Reset Zoom</button>
</div>
<!-- Main map -->
<div id="map"></div>
<!-- Right sidebar for AQI info and Weather -->
<div id="right-sidebar">
<h3>District AQI Details</h3>
<div id="aqi-info" class="section">
<p>Select a district from the left sidebar to view AQI details here.</p>
</div>
<h3>Weather Info</h3>
<div id="weather-info" class="section" style="line-height: 2.0;">
<p>Select a district to view weather details here.</p>
</div>
<div id="legend section">
<h4>Legend</h4>
<div><div class="legend-color" style="background-color: #00ff0d;"></div> 0-50: Good</div>
<div><div class="legend-color" style="background-color: #ffcc00;"></div> 51-100: Moderate</div>
<div><div class="legend-color" style="background-color: #ff9900;"></div> 101-150: Unhealthy for Sensitive</div>
<div><div class="legend-color" style="background-color: #ff6600;"></div> 151-200: Unhealthy</div>
<div><div class="legend-color" style="background-color: #ff3300;"></div> 201-300: Very Unhealthy</div>
<div><div class="legend-color" style="background-color: #9900cc;"></div> 301+: Hazardous</div>
</div>
<div id="data-source" class="section" style="margin-top: 80px; text-align: center;">
<p style="margin-bottom: 0.9px;">Data Source: <a href="https://openweathermap.org/api" target="_blank">OpenWeatherMap API</a></p>
</div>
</div>
</div>
<footer>
<p>Data Source: AQI Data Portal | Last Updated: November 2024</p>
</footer>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script>
const apiKey = '81416dd6c2425ae4865f21aa138b5f65'; // Add your OpenWeatherMap API key here
// Initialize the map
const map = L.map('map').setView([18.6400, 74.1000], 9); // Centering on Pune
// Add a tile layer
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© OpenStreetMap contributors'
}).addTo(map);
//Add WMS layer from GeoServer
const wmsLayer = L.tileLayer.wms('http://localhost:8080/geoserver/Geo27/wms', {
layers: 'Geo27:Pune', // Specify your layer here
format: 'image/png',
transparent: true,
attribution: "GeoServer"
}).addTo(map);
//administrative boundary
const adminLayer = L.tileLayer.wms('http://localhost:8080/geoserver/Geo27/wms',{
layers: 'Geo27:Pune Dissolve',
format: 'image/png',
transparent: true,
attribution: 'Administrative Boundary Layer',
zIndex: 1
});
// Additional WMS layer for Industry
const industryLayer = L.tileLayer.wms('http://localhost:8080/geoserver/Geo27/wms', {
layers: 'Geo27:industry', // Change this to your actual Industry layer name
format: 'image/png',
transparent: true,
attribution: "Industry Layer"
});
// Additional WMS layer for Plant Vegetation
const vegetationLayer = L.tileLayer.wms('http://localhost:8080/geoserver/Geo27/wms', {
layers: 'Geo27:veg', // Change this to your actual Plant Vegetation layer name
format: 'image/png',
transparent: true,
attribution: "Plant Vegetation Layer"
});
// Layer control to toggle layers on/off
const overlayMaps = {
"Talukas": wmsLayer,
"Administrative Boundary":adminLayer,
"Industry": industryLayer,
"Plant Vegetation": vegetationLayer
};
// Add layer control to toggle layers
L.control.layers(null, overlayMaps).addTo(map);
// Optionally, add any layer to the map by default
// industryLayer.addTo(map); // Uncomment this if you want to show the industry layer by default
// vegetationLayer.addTo(map); // Uncomment this if you want to show the vegetation layer by default
// Create a home button and add it to the map controls
var homeButton = L.control({position: 'topright'});
homeButton.onAdd = function(map) {
var button = L.DomUtil.create('a', 'leaflet-bar home-icon');
button.href = '#';
button.title = 'Home';
// Set the red home icon for the button
button.style.backgroundImage = "url('https://img.icons8.com/?size=100&id=80319&format=png&color=000000')"; // Red home icon
button.style.backgroundSize = '50px 50px'; // Size of the icon
button.style.width = '50px'; // Button width
button.style.height = '50px'; // Button height
button.style.border = 'none'; // Remove border
// When clicked, it resets the map view to the home coordinates
button.onclick = function() {
map.setView([18.6400, 74.1000], 9); // Reset to home location (Pune)
return false; // Prevent page refresh
};
return button;
};
homeButton.addTo(map);
// Dictionary to store district coordinates and AQI data
const districts = {
"Pune City": {coords: [18.5204, 73.8567], aqi: 70},
"Baramati": {coords: [18.151, 74.5764], aqi: 65},
"Junnar": {coords: [19.2, 73.8753], aqi: 78},
"Indapur": {coords: [18.113, 75.027], aqi: 80},
"Daund": {coords: [18.4655, 74.583], aqi: 55},
"Ambegaon": {coords: [19.03, 73.61], aqi: 90},
"Khed": {coords: [19.209, 73.854], aqi: 60},
"Shirur": {coords: [18.8265, 74.38], aqi: 85},
"Velhe": {coords: [18.2619, 73.6373], aqi: 40},
"Bhor": {coords: [18.1386, 73.8459], aqi: 75},
"Mulshi": {coords: [18.5183, 73.4562], aqi: 67},
"Maval": {coords: [18.7447, 73.6737], aqi: 58},
"Purandar": {coords: [18.2798, 74.1245], aqi: 85}
};
let currentMarker = null;
// Function to select and display district details
function selectDistrict(district, aqi) {
const { coords } = districts[district];
map.setView(coords, 11);
addMarker(coords, district, aqi);
updateAQIInfo(district, aqi);
highlightSelectedDistrict(district);
fetchWeather(coords[0], coords[1]); // Fetch weather data for the selected district
}
// Function to add a marker with colored circle
function addMarker(coords, district, aqi) {
if (currentMarker) {
map.removeLayer(currentMarker); // Remove the previous marker
}
// Define the color based on the AQI value
let markerColor = 'green'; // Default color for good AQI
if (aqi > 50) {
markerColor = 'yellow'; // Moderate AQI
}
if (aqi > 100) {
markerColor = 'orange'; // Unhealthy AQI
}
if (aqi > 150) {
markerColor = 'red'; // Very Unhealthy AQI
}
// Create a custom div icon with the determined color
const markerIcon = L.divIcon({
className: 'custom-icon',
html: `<div style="background-color: ${markerColor}; width: 25px; height: 25px; border-radius: 50%;"></div>`,
iconSize: [25, 25] // Size of the circle
});
// Add the marker with the custom icon
currentMarker = L.marker(coords, { icon: markerIcon }).addTo(map);
currentMarker.bindPopup(`<strong>${district}</strong><br>AQI: ${aqi}`).openPopup();
}
// Update AQI info in the sidebar
function updateAQIInfo(district, aqi) {
const aqiInfo = document.getElementById('aqi-info');
aqiInfo.innerHTML = `<strong>${district}</strong><br>AQI: ${aqi}`;
}
// Update AQI info in the sidebar
function updateAQIInfo(district, aqi) {
const aqiInfo = document.getElementById('aqi-info');
aqiInfo.innerHTML = `<strong>${district}</strong><br>AQI Level: ${aqi}<br>Air Quality: ${getAQICategory(aqi)}`;
}
// Function to determine AQI category based on AQI level
function getAQICategory(aqi) {
if (aqi <= 50) return "Good";
else if (aqi <= 100) return "Moderate";
else if (aqi <= 150) return "Unhealthy for Sensitive";
else if (aqi <= 200) return "Unhealthy";
else if (aqi <= 300) return "Very Unhealthy";
else return "Hazardous";
}
// Highlight selected district in the sidebar
function highlightSelectedDistrict(district) {
const listItems = document.querySelectorAll('#left-sidebar li');
listItems.forEach(item => {
item.classList.remove('selected');
if (item.textContent.includes(district)) {
item.classList.add('selected');
}
});
}
// Fetch and display weather data for the selected district
async function fetchWeather(lat, lon) {
const weatherInfo = document.getElementById('weather-info');
try {
const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}&units=metric`);
const data = await response.json();
const { temp, humidity } = data.main;
const { speed } = data.wind;
weatherInfo.innerHTML = `
<p><span class="bold-large">Temperature:</span> <span class="value-large">${temp}°C</span></p>
<p><span class="bold-large">Humidity:</span> <span class="value-large">${humidity}%</span></p>
<p><span class="bold-large">Wind Speed:</span> <span class="value-large">${speed} m/s</span></p>
`;
} catch (error) {
weatherInfo.innerHTML = '<p>Weather data unavailable</p>';
console.error("Weather fetch error:", error);
}
}
// Reset map to default view
function resetMap() {
map.setView([18.6400, 74.1000], 9);
if (currentMarker) {
map.removeLayer(currentMarker); // Remove marker
}
document.getElementById('aqi-info').innerHTML = '<p>Select a district from the left sidebar to view AQI details here.</p>';
document.getElementById('weather-info').innerHTML = '<p>Select a district to view weather details here.</p>';
}
</script>
</body>
</html>