block by andrewxhill b65a3d8c8a1733ffbcbe

Totally random

Full Screen

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Something crazy</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <link rel="shortcut icon" href="//cartodb.com/assets/favicon.ico" />
    <style>
      html, body, #map {
        height: 100%;
        padding: 0;
        margin: 0;
        background: #fff;
      }
    </style>
    <link rel="stylesheet" href="//libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
  </head>
  <body>
    <div id="map"></div>
    
    <!-- include cartodb.js library -->
    <script src="//libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>

    <script>
      function toColor(num) {
          num >>>= 0;
          var b = num & 0xFF,
              g = (num & 0xFF00) >>> 8,
              r = (num & 0xFF0000) >>> 16;
          return "rgb(" + [r, g, b].join(",") + ")";
      }
      function main() {

        // initiate our leaflet map
        map = L.map('map', { 
          zoomControl: true,
          center: [39, -98],
          zoom: 5
        })

        cartodb.createLayer(map, '//team.cartodb.com/api/v2/viz/75435924-3d33-11e4-818b-0e73339ffa50/viz.json')
                 .addTo(map)
                 .on('done', function(layer) {

                    var time = (new Date).getTime();
                    var color = toColor(time);
                    var value = Math.floor(Math.random()*10000)
                    layer.getSubLayer(0).setCartoCSS("#gilt_postal_codes{ polygon-fill: #ea4c88; [pop_total > "+value+"] { polygon-fill: "+color+";} polygon-opacity: 0.7; }");
                  });

        
      }

      window.onload = main; 
    </script>

  </body>
</html>