{"id":6084,"date":"2024-03-19T07:36:03","date_gmt":"2024-03-19T07:36:03","guid":{"rendered":"https:\/\/www.nema.go.ug\/new_site\/?p=6084"},"modified":"2025-04-16T05:16:21","modified_gmt":"2025-04-16T05:16:21","slug":"airquality","status":"publish","type":"post","link":"https:\/\/www.nema.go.ug\/en\/airquality\/","title":{"rendered":"AIR QUALITY"},"content":{"rendered":"\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<!-- Include Leaflet CSS and JS -->\r\n<p>&nbsp;<\/p>\r\n<p><script src=\"https:\/\/unpkg.com\/leaflet\/dist\/leaflet.js\"><\/script><\/p>\r\n<p>&nbsp;<\/p>\r\n<!-- Include jQuery -->\r\n<p><script src=\"https:\/\/code.jquery.com\/jquery-3.6.4.min.js\"><\/script><style>\r\n        #map {\r\n            height: 400px;\r\n        }\r\n    <\/style><\/p>\r\n<div id=\"map\">\u00a0<\/div>\r\n<p><script>\r\n        \/\/ Initialize Leaflet map\r\n        var map = L.map('map').setView([1.3733, 32.2903], 6); \/\/ Set initial view to Kampala, Uganda\r\n\r\n        \/\/ Add OpenStreetMap as the base layer\r\n        L.tileLayer('https:\/\/{s}.tile.openstreetmap.org\/{z}\/{x}\/{y}.png', {\r\n            attribution: '\u00a9 OpenStreetMap contributors'\r\n        }).addTo(map);\r\n\r\n        \/\/ Sample API endpoint and access token\r\n        var apiEndpoint = 'https:\/\/api.airqo.net\/api\/v2\/devices\/measurements\/grids\/{GRID_ID}';\r\n        var accessToken = \"WHGPBQBPUY7JWKCK\";\r\n\r\n        \/\/ Make API request\r\n        $.ajax({\r\n            url: apiEndpoint.replace('{GRID_ID}', '64b7ef42d7249f0029fed6e6').concat('?token=' + accessToken),\r\n            method: 'GET',\r\n            success: function(apiResponse) {\r\n                console.log(\"apiResponse\",apiResponse)\r\n                \/\/ Loop through measurements and add markers to the map\r\n                apiResponse.measurements.forEach(function(measurement) {\r\n    var lat = measurement.siteDetails.approximate_latitude;\r\n    var lon = measurement.siteDetails.approximate_longitude;\r\n    var pm25Value = Math.round(measurement.pm2_5.value); \/\/ Round off pm2_5 value\r\n    var siteName = measurement.siteDetails.description;\r\n    var aqiCategory = measurement.aqi_category;\r\n    var aqiColor = measurement.aqi_color;\r\n\r\n    \/\/ Create a marker with different colors based on AQI category\r\n    var marker = L.marker([lat, lon], {\r\n        icon: L.divIcon({\r\n            className: 'custom-marker',\r\n            iconSize: [20, 20],\r\n            iconAnchor: [10, 10],\r\n            popupAnchor: [0, -30],\r\n            html: '<div style=\"background-color: #' + aqiColor + '; width: 30px; height: 30px; border-radius: 50%; text-align: center; line-height: 30px; color: black;\">' + pm25Value + '<\/div>'\r\n\r\n        })\r\n    }).addTo(map)\r\n        .bindPopup('<b>' + siteName + '<\/b><br>PM2.5 Value: ' + pm25Value + '<br>AQI Category: ' + aqiCategory);\r\n});\r\n            },\r\n            error: function(error) {\r\n                console.error('Error fetching data:', error);\r\n            }\r\n        });\r\n    <\/script><\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u00a0<\/p>\n","protected":false},"author":7,"featured_media":19839,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ai_generated_summary":"","wpai_meta_description":"","footnotes":""},"categories":[79],"tags":[],"class_list":["post-6084","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-air-quality"],"_links":{"self":[{"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/posts\/6084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/comments?post=6084"}],"version-history":[{"count":2,"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/posts\/6084\/revisions"}],"predecessor-version":[{"id":26081,"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/posts\/6084\/revisions\/26081"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/media\/19839"}],"wp:attachment":[{"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/media?parent=6084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/categories?post=6084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nema.go.ug\/en\/wp-json\/wp\/v2\/tags?post=6084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}