Map Web Service:實時空氣質量圖塊API

Posted on September 18th 2015
(re-edited on December 31st 2019)
Share: aqicn.org/faq/2015-09-18/map-web-service-real-time-air-quality-tile-api/hk/


Map Overlay Process
(Attribution: Essentials of
Geographic Information Systems
)

We have been recently cooperating with quite a few more EPAs worlwide. Among all the requests which we have had, it is actually to provide a Web Map Service so that the EPA themselves can include the real-time Air Quality data onto the map from their website.

One of the obvious advantages of using such a map web service from us is to benefit from the transboundary data which we are curating, i.e. a world wide Air Quality information is provided without country boundary limits.

The second advantage is not only that this is a free service, but it is also completely compatible with standard map technologies from google, bing or leaflet, which allows a quick and easy integration with any existing website.


--

Tile Map Service Endpoint

The tile map server is available from the url `https://tiles.aqicn.org/tiles/{aqi}/{z}/{x}/{y}.png`, where aqi refers for the type of marker to be plotted, which can be:
  • usepa-aqi: Plots markers based on the composite AQI calculated with the US EPA standard.
  • usepa-pm25: PM2.5 based AQI - if a station does not have PM2.5 reading, then it is not plotted.
  • usepa-10: Same as above, but for PM10.
  • usepa-o3: Same as above, but for Ozone (based on the 1 hour breakpoints).
  • usepa-no2: Same as above, but for Nitrogen Dioxide.
  • usepa-so2: Same as above, but for Sulfur Dioxide.
  • usepa-co: Same as above, but for Carbon Monoxide.
  • asean-pm10: Asean PM10 raw PM10 concentration (explanations).
Below is the example for the 6 individual pollutants for South China.

Web-Service usage conditions

The map webservice is provided for free, under the condition of reasonable usage limits and acceptable usage policy. The tiles are currently refreshed every 15 minutes (and up to 1 hour in case of high traffic).

Note that our server capacity is limited, so we reserve the right to pause the service at any time, for instance to performance server maintenance. If you need a more stable integration, contact us to find a proper solution, such as setting-up a dedictated server.

Last you also need to specify your own token ID as an extra argument to the tile service endpoint, like `token=_TOKEN_ID_` in the following url: `https://tiles.aqicn.org/tiles/{aqi}/{z}/{x}/{y}.png?token=_TOKEN_ID_`. You can request your own token ID from this page. You just need to provide a valid email, and you can get your own token within a minute.

Web-Service usage restrictions

When using the service, please do not forget to provide the attribution to the World Air Quality Index project as well as the EPA providing the data (if you use the map service to show data from a specicic location or source). You can get the full list of all the EPA from this link.

As a matter of fact, do not act like the World Resource Institute (WRI): they were scrapping our entire data feed, and republishing the data on their own project website without giving any single attribution for our work... That's not quite ok when you know that they get funded up to 80 millions USD each year. Don't believe us? Check this snapshot.

Future extensions

We are already working on extending this webservice to provide more configuations. For instance:
  • To support for more standards other than the US EPA, such as `eucaqi-xxx` for the European Common Air Quality Index, `innaqi-xxx` for the Indian National Air Quality Index , `raw-xxx` for the unconverted raw data, etc.
  • More indicators such as the wind (both for the current wind speed and wind direction), as well as forecasted ventilation index [1] which can be extrememly usefull for forecasting.
  • Support for kriging geo-statistical surface estimation - i.e. heatmap like interpolations (picture on the right) which can be usefull for lower density monitoring network.
  • Support for 24 hours and 8 hours data averaging . Our map are currenly based on 1 hour averaging, but longer averaging period are useful for epidemilogicial studies.
  • Support for GeoJSON based tile rendering, allowing the customization of markers and color scale, as well as a better integration with tools like tuftjs.org.


Note that to support more AQI standards and tile configurations, we need to increase our server capacity (both processing power and Storage), for which we will require sponsorship. If you are working for one of the large cloud company, or for instance Google or Microsoft and reading this message, then why not considering making your company environmentally-friendly (combatting air pollution by promoting citizen awarness), and sponsoring part of the needed server extra capacity? That would not only help us, but also help the whole community of researchers, scientists, statisticians and epidemiologies working with environmental data and sciences.

--


Sample code: Integration with Leaflet

Leaflet is an extremely cool light-weight open-source JavaScript library for mobile-friendly interactive maps, created by Vladimir Agafonkin of MapBox.

Sample code:
  
<div  id='map'  style='height:380px;'  />  
<link  rel="stylesheet"  href="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.css"  />  
<script  src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>  
  
<script>  
      var  OSM_URL  =  'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';  
      var  OSM_ATTRIB  =  '&copy;  <a  href="http://openstreetmap.org/copyright">OpenStreetMap</a>  contributors';  
      var  osmLayer  =  L.tileLayer(OSM_URL,  {attribution:  OSM_ATTRIB});  
  
      var  WAQI_URL    =  "https://tiles.waqi.info/tiles/usepa-aqi/{z}/{x}/{y}.png?token=_TOKEN_ID_";  
      var  WAQI_ATTR  =  'Air  Quality  Tiles  &copy;  <a  href="http://waqi.info">waqi.info</a>';  
      var  waqiLayer  =  L.tileLayer(WAQI_URL,  {attribution:  WAQI_ATTR});  
  
      var  map  =  L.map('map').setView([51.505,  -0.09],  11);  
      map.addLayer(osmLayer).addLayer(waqiLayer);  
</script>

Sample code: Integration with Google

Google maps are quite convinient and free up to 25,000 API calls a day. Note that google maps is available in china, but the maps API script needs to be loaded from google.cn (`http://maps.google.cn/maps/api/js`) instead of the regular https://maps.googleapis.com/maps/api/js url.

  
  
<div  id='map'  style='height:380px;'  />  
<script  src="https://maps.googleapis.com/maps/api/js"></script>  
  
<script>  
      var  map  =  new  google.maps.Map(document.getElementById('map'),  {  
                  center:  new  google.maps.LatLng(51.505,  -0.09),  
                  mapTypeId:  google.maps.MapTypeId.ROADMAP,  
                  zoom:  11  
              });  
  
                              var  t  =  new  Date().getTime();  
      var  waqiMapOverlay  =  new  google.maps.ImageMapType({  
                  getTileUrl:  function(coord,  zoom)  {  
                            return  'https://tiles.aqicn.org/tiles/usepa-aqi/'  +  zoom  +  "/"  +  coord.x  +  "/"  +  coord.y  +  ".png?token=_TOKEN_ID_";  
                  },  
                  name:  "Air  Quality",  
        });  
  
      map.overlayMapTypes.insertAt(0,waqiMapOverlay);  
</script>

Sample code: Integration with Microsoft Bing Maps

Bing maps are actually quite cool, and also using Here base map for some countries. There are still quite a lot of web site based on Microsoft Maps (and especially in the domain of Air Quality and weather).

  
  
<div  id='map'  style='height:380px;'    style='position:relative;'/>  
<script  type='text/javascript'  src='https://www.bing.com/api/maps/mapcontrol?callback=initBingMap'  async  defer></script>  
  
<script>  
      function  initBingMap()  {  
  
            var  map  =  new  Microsoft.Maps.Map(document.getElementById('map'),  {      
                        center:  new  Microsoft.Maps.Location(51.505,  -0.09),    
                        zoom:11,  
            }  );  
  
            var  options  =  {    
                  uriConstructor:  "https://tiles.aqicn.org/tiles/usepa-aqi//{zoom}/{x}/{y}.png?token=_TOKEN_ID_",  
                  minZoom:  1,  
                  maxZoom:  15  
            };  
            var  waqiTileSource  =  new  Microsoft.Maps.TileSource(options);  
            var  waqiTilelayer  =  new  Microsoft.Maps.TileLayer({  mercator:  waqiTileSource  });  
            map.layers.insert(waqiTilelayer);  
      }  
</script>



[1] Also refered as venting index or cumulated wind power


Click here to see all the FAQ entries
  • AQI量表:顏色和數字是什麼意思?
  • 使用統計距離進行實時傳感器網絡驗證
  • 克里格插值

  • Read or publish comments (they rely on Disqus)

    關於空氣質量與空氣污染指數

    本網站採用的污染指數和顏色與EPA是完全相同的。 EPA的指數可以從 AirNow上查到

    空气质量指数空气质量指数级别(状况)及表示颜色对健康影响情况建议采取的措施
    0 - 50一级(优)空气质量令人满意,基本无空气污染各类人群可正常活动
    51 -100二级(良)空气质量可接受,但某些污染物可能对极少数异常敏感人群健康有较弱影响极少数异常敏感人群应减少户外活动
    101-150三级(轻度污染)易感人群症状有轻度加剧,健康人群出现刺激症状儿童、老年人及心脏病、呼吸系统疾病患者应减少长时间、高强度的户外锻炼
    151-200四级(中度污染)进一步加剧易感人群症状,可能对健康人群心脏、呼吸系统有影响儿童、老年人及心脏病、呼吸系统疾病患者避免长时间、高强度的户外锻炼,一般人群适量减少户外运动
    201-300五级(重度污染)心脏病和肺病患者症状显著加剧,运动耐受力降低,健康人群普遍出现症状儿童、老年人及心脏病、肺病患者应停留在室内,停止户外运动,一般人群减少户外运动
    300+六级(严重污染)健康人群运动耐受力降低,有明显强烈症状,提前出现某些疾病儿童、老年人和病人应停留在室内,避免体力消耗,一般人群避免户外活动
    (参考详见http://zh.wikipedia.org/wiki/空气质量指数)

    如果你想了解更多有關空氣質量與污染,詳見維基百科或者 AirNow

    有關健康建議詳​​見北京的Richard Saint Cyr MD醫生的博客:www.myhealthbeijing.com


    注意事項: 所有空氣品質數據在發佈時均未經驗證,且為了確保資料準確性,這些數據可能隨時被修改,恕不另行通知。 世界空氣品質指數專案在編制這些訊息內容時已經謹慎的運用了所有適當的技巧,在任何情況下世界空氣品質指數在任何情況下,世界空氣品質指數專案團隊或其代理人均不對因提供此數據而直接或間接引起的任何損失、傷害或損害來承擔契約、侵權或其他責任。



    設定


    選擇語言:


    Temperature unit:
    Celcius