MapLibre + CARTO

by felixp

HTML

<!DOCTYPE html>
<html>

  <head>
    <title>MapLibre + CARTO</title>
    
    <!-- Maplibre & deck.gl imports -->
    <script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
    <link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet" />
    <!--script src="https://unpkg.com/[email protected]/dist.min.js"></script-->
    <script src="https://unpkg.com/[email protected]/dist.min.js"></script>

  </head>

  <body>
    <div id="map"></div>
  </body>
</html>

CSS

body {
  margin: 0;
  padding: 0; 
}
#map{
  width: 100vw;
  height: 100vh;
}

JavaScript

const AIRPORTS = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/line/airports.json'

const deckgl = new deck.DeckGL({
  // Basemap style
  container: 'map',
  // map: maplibregl, // <-- No longer necessary in 8.9
  // Can also use 'positron', 'dark-matter' instead of voyager
  mapStyle: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",

  // Initial map location
  initialViewState: {
    latitude: 50,
    longitude: 10,
    zoom: 3,
  },
  controller: true,

  // Visualization overlay
  layers: [
    new deck.ScatterplotLayer({
      data: AIRPORTS,
      getPosition: d => d.coordinates,
      getFillColor: d => d.type === "major" ? [238, 0, 0] : [238, 77, 90],
      radiusMinPixels: 3
    }),
  ]
});