Globe projection

Estimated reading time: 1 minute

Use the code sample below to load a map with a globe projection.

View on GitHub

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8" />
    <link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet" />
    <script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
    <style>
      html,
      body {
        margin: 0;
        padding: 0;
        height: 100%;
      }
      #map {
        min-height: 500px;
        height: 100%;
        width: 100%;
        background: #233160;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      (async () => {
        // Don't forget to replace <YOUR_ACCESS_TOKEN> by your own access token
        const accessToken = "<YOUR_ACCESS_TOKEN>";

        // Get the style then entend it with the globe projection
        const style = await fetch(`https://api.jawg.io/styles/jawg-terrain.json?access-token=${accessToken}`)
          .then((response) => response.json())
          .then((style) => {
            return {
              ...style,
              projection: {
                type: "globe",
              },
            };
          });

        const map = new maplibregl.Map({
          container: "map",
          style: style,
          zoom: 2,
          center: [0, 0],
          maxPitch: 85,
          canvasContextAttributes: { antialias: true },          
        }).addControl(new maplibregl.NavigationControl(), "top-right");
        // This plugin is used for right to left languages
        maplibregl.setRTLTextPlugin("https://unpkg.com/@mapbox/[email protected]/mapbox-gl-rtl-text.min.js");
      })();
    </script>
  </body>
</html>