deck.gl LineLayer Example

Demo

Source

<html>
  <head>
    <title>deck.gl LineLayer Example</title>

    <script src="https://unpkg.com/deck.gl@^9.0.0/dist.min.js"></script>
    <script src='https://unpkg.com/maplibre-gl@3.6.0/dist/maplibre-gl.js'></script>

    <link href='https://unpkg.com/maplibre-gl@3.6.0/dist/maplibre-gl.css' rel='stylesheet' />
    <style type="text/css">
      body {
        width: 100vw;
        height: 100vh;
        margin: 0;
        overflow: hidden;
      }
      .deck-tooltip {
        font-family: Helvetica, Arial, sans-serif;
        padding: 6px !important;
        margin: 8px;
        max-width: 300px;
        font-size: 10px;
      }
    </style>
  </head>

  <body>
    <div id="tooltip"></div>
  </body>

  <script type="text/javascript">

    const {DeckGL, LineLayer} = deck;

    new DeckGL({
      mapStyle: 'https://basemaps.cartocdn.com/gl/dark-matter-nolabels-gl-style/style.json',
      initialViewState: {
        latitude: 51.51,
        longitude: -0.11,
        zoom: 8,
        maxZoom: 16,
        pitch: 50,
        bearing: 0
      },
      controller: true,
      layers: [
        new LineLayer({
          id: 'line',
          data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/line/heathrow-flights.json',
          opacity: 0.8,
          pickable: true,
          getSourcePosition: d => d.start,
          getTargetPosition: d => d.end,
          getColor: d => getColor(d),
          getWidth: 8
        })
      ],
      getTooltip: ({object}) => object && `Flight ${object.name}`
    });

    function getColor(d) {
      const z = d.start[2];
      const r = z / 10000;
      return [255 * (1 - r * 2), 128 * r, 255 * r, 255 * (1 - r)];
    }
    
  </script>
</html>