Skip to content
MapLibre GL JS

MapLibre GL JS

On this page

MapLibre GL JS is an open-source JavaScript library for rendering interactive vector maps in the browser. It uses WebGL to render maps from vector tile sources - including Maptoolkit’s vector and terrain tiles.

You’ll need a Maptoolkit API key to use the tile endpoints - see Authentication to get one.

Installation

CDN

MapLibre GL JS 6 is an ES module. An import map tells the browser where to load maplibre-gl from, and your code imports it in a <script type="module">:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@6.16.0/dist/maplibre-gl.css" />
<script type="importmap">
  {
    "imports": {
      "maplibre-gl": "https://cdn.jsdelivr.net/npm/maplibre-gl@6.16.0/dist/maplibre-gl.mjs"
    }
  }
</script>
<script type="module">
  import * as maplibregl from "maplibre-gl";
  // your map code
</script>

Variables in a module are not global. If an onclick attribute in your HTML calls a function, assign that function to window, or attach the listener with addEventListener.

Open a copied example through a local web server, not as a file. A page opened from file:// cannot start the MapLibre GL JS 6 worker, and it sends no origin, so the Maptoolkit endpoints answer with 403. From the folder with the HTML file, start a server and open http://localhost:8000/ in the browser:

python -m http.server 8000

npm

npm install maplibre-gl
import * as maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';

Basic setup

Pass the Maptoolkit style URL directly as the style parameter. Your API key goes in the query string:

const map = new maplibregl.Map({
  container: 'map',
  attributionControl: { compact: false },
  style: 'https://styles.maptoolkit.net/maptoolkit/maptoolkit.summer.json?api_key=YOUR_API_KEY',
  center: [16.37, 48.21],
  zoom: 12,
});

Available styles

All seven styles take the same URL shape, with the variant name in the middle:

Style URLDescription
https://styles.maptoolkit.net/maptoolkit/maptoolkit.summer.json?api_key=…Outdoor and terrain, the default
https://styles.maptoolkit.net/maptoolkit/maptoolkit.winter.json?api_key=…Winter, with pistes and lifts
https://styles.maptoolkit.net/maptoolkit/maptoolkit.hiking.json?api_key=…Hiking, with trail difficulty grades
https://styles.maptoolkit.net/maptoolkit/maptoolkit.cycling.json?api_key=…Cycling, with routes and node networks
https://styles.maptoolkit.net/maptoolkit/maptoolkit.street.json?api_key=…Detailed street map
https://styles.maptoolkit.net/maptoolkit/maptoolkit.light.json?api_key=…Minimal light
https://styles.maptoolkit.net/maptoolkit/maptoolkit.dark.json?api_key=…Dark, high contrast

Plugins

Maptoolkit publishes open-source plugins for MapLibre GL JS. Each one is an npm package. You add the controls with map.addControl() and the 3D layers with map.addLayer():

PluginWhat it does
Style ControlLets users switch between map styles from a thumbnail panel.
Logo ControlAdds the Maptoolkit logo to the map.
Isochrone ControlLets users drag a marker onto the map and shows how far they can travel in a given time.
Legend ControlShows a legend of the map features currently in view.
Scene3D ControlShows the 3D buildings and trees of a Maptoolkit style, with roof shapes and city models.
3D LayersCustom layers that draw 3D buildings with roof shapes and glTF models.

See Our MapLibre Plugins for all plugins and how to use them without a bundler.

Using the Maptoolkit MCP

If you use an AI tool with the Maptoolkit MCP Server, you can generate MapLibre + Maptoolkit code in a single prompt without needing to look up style URLs or tile formats manually.