cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <header>
   <img class="logo" align="right" src="https://data-canvas-neighborhoods.herokuapp.com/logo.svg"/>
   <h1>Experiment 2: Light</h1>
</header>
<section id="place">
   <div id="controls">
      <div class="select-dropdown"><select id="cities"></select></div>
     <div class="select-dropdown"><select id="select_sensor"></select></div>
   </div>
   <div class="overlay"></div>
   <div id="map">
     <!-- Visualization goes here above the map -->
   </div>
   <div id="legend">
     <div class="label">Light</div>
     <div class="label min">0 LUX</div>
     <div class="label max">10,000 LUX</div>
     <div class="items"></div>
   </div>
</section>

            
          
!
            
              #place .overlay {
  font-size: 4vmin;
   line-height: 2vmin;
   height: 44%;
   margin-top:8%;
   width: 80%;
   text-shadow: 0.3vmin 0.3vmin 0.6vmin #000;
}

#place .overlay .value {
    bottom: 1vw;
    right: 0px;
    font-size: 6.4vmin;
    position: absolute;
}

#place .overlay .value .unit {
   font-size: 4.4vmin;
}

#place .overlay .address {
   font-size: 7.4vmin;
   text-shadow: .5vmin .5vmin 1vmin #000;
}

#place #legend .item {
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border-right: 0.1vw solid #ccc;
  float: left;
  height: 9.9vw;
  width: 9.69vw;
}

#place #legend .item:last-child {
  border-right: none;
}

header {
   height: 2%;
   min-height: 32px;
   font-weight: 300;
}

header img {
    margin: 1vmin;
    min-width: 140px;
    position: absolute;
    right: 1vmin;
    top: 1vmin;
}

header h1 {
  font-size: 4.2vmin;
  font-weight: 400;
  line-height: 3vmin;
  margin-left: 1vw;
}


            
          
!
            
              var url = "http://sensor-api.localdata.com/api/v1/";
var current_place = null;
var current_sensor = null;
var current_city = null;

function visualizeData(data) {

  // Do something with the data
  // dust, humidity, light, light_summary, noise, pollution, pollution_summary, temperature

  // LUX is lumens per square meter
  var max = 10000;
  var scale = 2;

  var percentage = Math.round((data.light / max) * 10) / 10;
  var value = percentage * scale;
  // Only make the panel
  if (value < 0.4) { value = 0.4; }
  // Create a css 3 filter representing the brightness
  var filter = "brightness(" + Math.round(value * 10) / 10 + ") contrast(" + (1.2) + ")";
   
  $("#place").find('.overlay').find('.value').html(Math.round(data.light) + ' <span class="unit">LUX</span>');

  // Use the CSS3 Brightness fitler
  $("#map").css('filter', filter );
  $("#map").css('-webkit-filter', filter );
  $("#legend").find(".items").html("");

  // Create a legend that shows the different levels of light
  for (var i = 0; i < 10; i++) {
    var filter = "brightness(" + 2 * (1 / (i + 1)) + ")";
     

    var div = $("<div class='item'></div>");
    div.css("background-image", "url('https://data-canvas-neighborhoods.herokuapp.com/images/legend/" + city_id + ".png')");
    div.css('filter', filter );
    div.css('-webkit-filter', filter );
    $("#legend").find(".items").prepend(div)
  }

}

function getPlace(place) {

  // Reverse Geocode the current place
  var coord = L.latLng(place.Y, place.X);
  getAddress(coord, showAddress)

  function showAddress(result) {
     $("#place").find(".overlay").find(".address").html(result.address_components[0].short_name);

    current_place = result;

    if (place.id == undefined) {
      current_place.sensor = getNearestSensor(map);
    } else {
      current_place.sensor = place;
    }

    sensor = current_place.sensor;

    if (sensor !== null) {

      // Fetch the latest data at an interval
      getSensorData(current_place.sensor, 10, visualizeData);

      // Create a marker and store it with the place
      clearMap(map, current_layer);
      showSensorMarker(coord, map);
    }
  }
}

$(document).ready(function() {

  // Initialize the map and geocoder
  map = L.mapbox.map('map', side_map, map_options).setView([37.77072000222513, -122.4359575], 12);
  new L.Control.Zoom({ position: 'bottomright' }).addTo(map);

  _.each(cities, function(city){
    $("#cities").append("<option value='" + city.name + "'>" + city.name + "</option>");
  });

  selectCity();
  $("#cities").unbind().on("change", function(){
    selectCity();
  });

  $("#select_sensor").unbind().on("change", function(){

    var id = $(this).val();
    var selected = _.findWhere(sensors, { id : id });

    if (selected !== null) {
      clearMap(map)
      selectSensor(selected, getPlace)
    }
  });

  function selectCity() {

    city_name = $("#cities").val();
    var id = city_name.toLowerCase().split(" ").join("-");

    city_id = id;

    $("#place").find(".overlay").html('<h2 class="value"></h2><div class="photo"></div><h1>' + city_name + '</h1><h2 class="address"></h2>');


    // Fetch Neighborhoods or Districts for current city
    $.getJSON('https://s3-us-west-2.amazonaws.com/s.cdpn.io/230399/' + id + ".json", function(data){
      hoods = data;
      showCityLayer(data, map, showCity, getPlace);
    });

    function showCity(){
      var center = map.getCenter();
      var coord = L.latLng(center.lat, center.lng);

      getTimezone(coord, function(result){
        var timezone = result.timeZoneId;
        var now = moment.tz(now, timezone);

        $("#place").find(".overlay").append("<h2>" + now.format("LT") + "</h2>")

        fetchCityData(city_name, timezone, visualizeData);
      });

    }

    sensors = _.findWhere(cities, { name : city_name });
    sensors = sensors.sensors;

    sensor_layer = L.featureGroup();

    $("#select_sensor").html('<option value="none">Select a Sensor</option>');
    _.each(sensors, function(sensor){
      $("#select_sensor").append("<option value='" + sensor.id + "'>" + sensor.hood + " - " + sensor.name + "</option>");
      showSensor(sensor, map, getPlace)
    });
    sensor_layer.addTo(map);
    map.fitBounds(sensor_layer.getBounds());
  }
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console