Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- https://sites.google.com/view/mapbox-decompress-2018/map-2?authuser=0 -->
<script src='https://api.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css' rel='stylesheet' />

<body>
  <!--initiate map container...sdf. -->
  <div id='map'></div>
  <div class='map-overlay' id='title'><h2>New and Proposed Building Development within the City of Melbourne</h2>
    <p>Toggle on and off buildings by development status below. Hover over the new buildings for further information</p></div>
    <div class='map-overlay' id='source'><t>Source: 3D development data from City of Melbourne, Feb 2018, available under
      <a href="https://creativecommons.org/licenses/by/3.0/au/deed.en">creative commons licence</a> via
      <a href="https://data.melbourne.vic.gov.au/Property-Planning/3D-Development-Activity-Model-Footprints/def8-4wbt">
        Melbourne Data</a> </t></div>
        <nav id='button'></nav>

<script>
mapboxgl.accessToken = 'pk.eyJ1IjoidG9wYXp0ZWUiLCJhIjoiY2pmMzhsdWJnMGJndzJ3cDQxM2pnN3NnOCJ9.8Zz6EAAOwabhDKbI6BoJXA';

 
  // create the map
  var map = new mapboxgl.Map({
    container: 'map', // container id
    style: 'mapbox://styles/mapbox/light-v9',
    maxZoom: 17, // set maxZoom
    minZoom: 13, // set minZoom
    maxBounds: [[144.9,-37.85],[145.0,-37.8]],
    bearing: 15,  // direction
    pitch: 60, // angle
    zoom: 15, // default zoom level
    center: [144.965, -37.815] // default location
  });


  map.on('load', function() {

    var popup = new mapboxgl.Popup({
      closeButton: false,
      closeOnClick: false
    });
    //add map source for current buildings layer:
    map.addSource('buildingSource', {
      'type': 'vector',
      'url': 'mapbox://mapbox.mapbox-streets-v7'
    }
  );

    map.addLayer({
      'id': 'currentbuildings',
      'source': 'buildingSource',
      'source-layer': 'building',
      'type': 'fill-extrusion',
      'paint': {
        'fill-extrusion-color': '#999999',
        'fill-extrusion-height': {
          'type': 'identity',
          'property': 'height'
        },
        'fill-extrusion-opacity': 0.7
      }
    });


    // variable arrays for status names and their colours - in stored tileset
    var statusNames = ['APPLIED', 'APPROVED', 'UNDER CONSTRUCTION', 'COMPLETED'];
    // colorbrewer colours every 2nd from 6-class YlGnBu
    var statusColors = ['#08519c', '#6baed6', '#c6dbef', '#999999'];

    // add the source layer for new building development data:
    // map.addSource('myLayer', {
    //   'type': 'vector',
    //   'url': 'mapbox://sgeoviz.2m5ilbt9'
    // });


    // Colour layers by their status and add an interactive legend
    for (var i = 0; i < statusNames.length; i++) {
      var statusName = statusNames[i];
      var statusColor = statusColors[i];

      map.addLayer({
        'id': statusName,
        'source': {
          'type': 'vector',
          'url': 'mapbox://sgeoviz.2m5ilbt9'
        },
        'source-layer': 'DevelopmentFootprint_OpenData-ciw5bu',
        'type': 'fill-extrusion',
        'paint': {
          'fill-extrusion-height': {
            'type': 'identity',
            'property': 'bldhgt_ahd'
          },  'fill-extrusion-color': statusColor,
          'fill-extrusion-opacity': 0.7
        },
        'filter': ['==', 'status', statusName]

      });


// automatic popup open/close -- adapted from this example: https://www.mapbox.com/mapbox-gl-js/example/popup-on-hover/
// when mouse inside the layer we just created then do this:
map.on('mouseenter', statusName, function(e) {
  // Change the cursor style to pointer.
  map.getCanvas().style.cursor = 'pointer';
  // give the popup coordinates and populate the popup with text
  popup.setLngLat(e.lngLat)
  .setHTML(e.features[0].properties.status
    + ": " + e.features[0].properties.address
    + "<br> Expected Height: " + e.features[0].properties.bldhgt_ahd + "m / "
    + e.features[0].properties.num_floors + " storys <br> Proposed Use: "
    + e.features[0].properties.land_use_1 + ", "
    + e.features[0].properties.land_use_2 + ", "
    + e.features[0].properties.land_use_3
  )
  .addTo(map);
});
// when mouse out of building then remove popup automatically:
map.on('mouseleave', statusName, function() {
  map.getCanvas().style.cursor = '';
  popup.remove();
});
createButtons(statusName, statusColor);
};


});

map.addControl(new mapboxgl.NavigationControl());

// function where buttons are created and visibilty of layers on/off.
// adapted from Lab 5 code, adapted from https://www.mapbox.com/mapbox-gl-js/example/toggle-layers/
// This will later be adapted to also create buttons for filter by land use type / 3D/2D etc (version 3)
function createButtons(name, colour){

  var link = document.createElement('a');
  link.href = '#';
  link.className = 'active';
  link.textContent = name;
  link.style.backgroundColor = colour;

  link.onclick = function(e) {
    var clickedLayer = this.textContent; // hard coded for 3D layers
    e.preventDefault();
    e.stopPropagation();

    var visibility = map.getLayoutProperty(clickedLayer, 'visibility');
    // make layer visible / not visible when clicked.
    // hard coding to combine the currentbuildings with completed buildings ** to be improved in version 3 **
    if (clickedLayer == "COMPLETED" && visibility === 'visible')
    {
      map.setLayoutProperty(clickedLayer, 'visibility', 'none');
      map.setLayoutProperty('currentbuildings', 'visibility', 'none');
      this.className = '';
    }
    else if (visibility === 'visible') {
      map.setLayoutProperty(clickedLayer, 'visibility', 'none');
      this.className = '';
    }
    else if (clickedLayer == "COMPLETED")
    {
      map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
      map.setLayoutProperty('currentbuildings', 'visibility', 'visible');
      this.className = 'active';
    }
    else {
      this.className = 'active';
      map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
    }

  };

  var layers = document.getElementById('button');
  layers.appendChild(link);

}; // end createButtons function
  </script>
  </body>

The data contains the footprints and building information about recently developed buildings, those under development, approved for development and under consideration for planning permission
              
            
!

CSS

              
                
body {
  margin: 0;
  padding: 0;
}

h2{
  margin-left: 10px;
  font-size: 1.2em;
}

p {
  font-size: 0.8em;
  margin-left : 10px;
  text-align: left;
}

t {
  font-size: 0.7em;
  text-align: left;
}

/**
* Create a position for the map
* on the page */
#map {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
}

/**
* Set rules for how the map overlays
* (info box and legend) will be displayed
* on the page. */
.map-overlay {
  position: absolute;
  background: rgba(255, 255, 255, 0.8);
  font-family: 'Helvetica Neue', Helvetica, Arial, Sans-serif;
  overflow: auto;
  border-radius: 3px;
  margin: 20px;
}

.mapboxgl-popup {
  max-width: 400px;
  font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
}

#source {
  padding: 5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  line-height: 10px;
  height: 8px;
  margin-bottom: 30px;
  width: 650px;
  bottom: 0;
}

#title {
  top: 0px;
  height: 85px;
  width: 670px;
}

#button {
  background: #fff;
  position: absolute;
  z-index: 1;
  top: 120px;
  left: 20px;
  border-radius: 3px;
  width: 120px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  font-family: 'Arial', sans-serif;
  color: white;
  font-weight: normal;
}

#button a {
  font-size: 13px;
  color: #404040;
  display: block;
  margin: 0;
  padding: 0;
  padding: 10px;
  text-decoration: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  text-align: center;
  border: none;
  font-weight: normal;
}


#button a:hover {
  color: #404040;
  font-weight: bold;
}

#button a.active {
    color: white;
    font-weight: normal;
}
#button a.active:hover {
  color: #404040;
  font-weight: bold;
}
              
            
!

JS

              
                
              
            
!
999px

Console