Climate Orgs

East Bay

by nicolejlj

HTML

<script src="http://processingjs.org/js/pjs/processing.min.js"></script>
<script src="http://processingjs.org/js/pjs/init.js"></script>
<title>East Bay Climate Programs</title>
<div id="floating-panel">
  <button onclick="toggleHeatmap()">Toggle Heatmap</button>
  <button onclick="changeGradient()">Change gradient</button>
  <button onclick="changeRadius()">Change radius</button>
  <button onclick="changeOpacity()">Change opacity</button>
<div id="map"></div>
<script async defer
        src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAgxG27_LrZPAHVYPpQiYf1e7ErxT9uZwQ&libraries=visualization">
    </script>

CSS

#map {
  height: 100%;
  width:  100%;
}
html, body {
  height: 100%;
  width:  100%;
  margin: 0;
  padding: 0;
}
#floating-panel {
  position: absolute;
  top: 10px;
  left: 25%;
  z-index: 5;
  background-color: #fff;
  padding: 5px;
  border: 1px solid #999;
  text-align: center;
  font-family: 'Roboto','sans-serif';
  line-height: 30px;
  padding-left: 10px;
}
#floating-panel {
  background-color: #fff;
  border: 1px solid #999;
  left: 25%;
  padding: 5px;
  position: absolute;
  top: 10px;
  z-index: 5;
}

JavaScript

var map, heatmap;

function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    center: {lat: 37.862006, lng: -122.282255},
    mapTypeId: 'roadmap'
  });

  heatmap = new google.maps.visualization.HeatmapLayer({
    data: getPoints(),
    map: map
  });
}

function toggleHeatmap() {
  heatmap.setMap(heatmap.getMap() ? null : map);
}

function changeGradient() {
  var gradient = [
    'rgba(0, 255, 255, 0)',
    'rgba(0, 255, 255, 1)',
    'rgba(0, 191, 255, 1)',
    'rgba(0, 127, 255, 1)',
    'rgba(0, 63, 255, 1)',
    'rgba(0, 0, 255, 1)',
    'rgba(0, 0, 223, 1)',
    'rgba(0, 0, 191, 1)',
    'rgba(0, 0, 159, 1)',
    'rgba(0, 0, 127, 1)',
    'rgba(63, 0, 91, 1)',
    'rgba(127, 0, 63, 1)',
    'rgba(191, 0, 31, 1)',
    'rgba(255, 0, 0, 1)'
  ]
  heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}

function changeRadius() {
  heatmap.set('radius', heatmap.get('radius') ? null : 20);
}

function changeOpacity() {
  heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}


/* Data points defined as an array of LatLng objects */
var heatmapData = [
          new google.maps.LatLng(37.782551, -122.445368),
          new google.maps.LatLng(37.889456, -122.296076),
          new google.maps.LatLng(37.889456, -122.296076),
          new google.maps.LatLng(37.889456, -122.296076),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.872626, -122.273808),
          new google.maps.LatLng(37.913618,...