Cartographer.js

Cluster Map demo – Benzene pollutant data

A Google Spreadsheet was used to pull in data from the EPA regarding the average levels of benzene airborne pollutants (in ppbC) at monitoring stations across the US for the year 2008. You can access the original data here. This data can be fed into Cartographer's cluster method to render area-scaled circles showing relative levels of benzene concentration.

var cartographer; 

function getSpreadsheet( key, wsid ) {
  // Retrieve JSON feed from Google Spreadsheets.
  var script = document.createElement( 'script' );
  script.setAttribute( 'src', 'http://spreadsheets.google.com/feeds/list'
    + '/' + key + '/' + wsid + '/public/values' +
    '?alt=json-in-script&callback=loadMapJson' );
    script.setAttribute( 'id', 'jsonScript' );
    script.setAttribute( 'type', 'text/javascript' );
  document.documentElement.firstChild.appendChild( script );
}

function loadMapJson( json ) { 
  var data = [];
  for( var i = 0; i < json.feed.entry.length; i++ ) {
    var entry = json.feed.entry[i];
    var lat = parseFloat( entry["gsx$_d2mkx"].$t );
    var lng = parseFloat( entry["gsx$_cssly"].$t );
    var val = parseFloat( entry["gsx$_ckd7g"].$t );
    var state = entry["gsx$_d180g"].$t;
    var lbl = state + ": " + val;
    if( lat && parseFloat(lat) > 0 ) { 
      data.push( { lat:lat, lng:lng, val:val, label:lbl } );
    }
  }
  cartographer.cluster( data, { gridSize:30.0, combine:function(a,b){return .5*(a+b);} } );
}

function load() {
  if( GBrowserIsCompatible() ) {
    var map = new GMap2(document.getElementById("map"));
    map.enableScrollWheelZoom();
    map.setCenter(new GLatLng(18, 0), 2);
    map.addControl(new GLargeMapControl());
    map.addControl(new GHierarchicalMapTypeControl());
    cartographer = Cartographer( map, { colorize:"#000", colorizeAlpha:.6 } );
    getSpreadsheet( "t67GSpfiuIGpUtCT92_bRsg", "od6" );
  }
}