Use a custom style from Jawg Lab

Estimated reading time: 1 minute

Check out this code sample that allows you to add a custom style to your map, using the MapLibre GL JS library.

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%;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      // Don't forget to replace <YOUR_ACCESS_TOKEN> by your own access token
      const accessToken = "<YOUR_ACCESS_TOKEN>";
      // Set your custom style ID. To get your custom style ID see https://www.jawg.io/docs/maps#get-custom-style-id
      const styleId = "<YOUR_CUSTOM_STYLE_ID>";
      var map = new maplibregl.Map({
        container: "map",
        style: `https://api.jawg.io/styles/${styleId}.json?access-token=${accessToken}`,
        zoom: 13,
        center: [-91.18764, 30.44581],
      }).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>