deck+Google HexagonLayer

by carto

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>deck.gl+Google</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <script src="https://unpkg.com/@loaders.gl/[email protected]/dist/dist.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist.min.js"></script>
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&v=beta&map_ids=fae05836df2dc8bb"
    ></script>
    <!-- jsFiddle will insert css and js -->
  </head>
  <body>
    <div id="map"></div>   
  </body>
</html>

CSS

/* Always set the map height explicitly to define the size of the div element that contains the map. */
#map {
  height: 100%;
}

/* Optional: Makes the sample page fill the window. */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

JavaScript

const DATA_URL =
  'https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv';

function initMap() {
  
  //Create the Google Maps Object
  const map = new google.maps.Map(document.getElementById("map"), {
    center: {lat: 52, lng: -1.4},
    mapId: '84591267f7b3a201',
    tilt: 40.5,
    zoom: 7
  });
  
const colorRange = [
  [1, 152, 189],[73, 227, 206],[216, 254, 181],
  [254, 173, 84],[209, 55, 78]];
  
  //Create an HexagonLayer visualization
  const hexagonLayer = new deck.HexagonLayer({
    id: 'hexagon',
    colorRange,
    coverage: 1,
    data: fetch(DATA_URL)
      .then(response => response.arrayBuffer())
      .then(buffer => CSVLoader.parse(buffer)),
    elevationRange: [0, 3000],
    elevationScale: 50,
    extruded: true,
    getPosition: d => [d.lng, d.lat],
    radius: 1000
  });

//Create an overlay on Google Maps with the layer
  const overlay = new deck.GoogleMapsOverlay({
    layers: [hexagonLayer]
  });
  //add that overlay to the Google Map
  overlay.setMap(map);
}



initMap();