There are two ways how to display OpenMapTiles with OpenLayers library: using raster or vector tiles.

Raster tiles from server

OpenLayers doesn’t support vector tiles by default. Raster tiles can be generated on demand for any of the GL styles with the open-source server software called TileServer GL. Such raster tiles can be displayed using ol.source.XYZ source.

Vector tiles with a plugin

Vector tiles can be displayed in OpenLayers using the ol-mapbox-style plugin together with OpenMapTiles. Read the following guideline or check out the code here.

Convert Mapbox GL style to OpenLayers style functions

The ol-mapbox-style converts the original Mapbox GL style specification into OpenLayers style functions. This extension enables you to design maps for vector tiles using the existing tools and then switch to a different renderer.


Create an HTML page and include OpenLayers with the standalone build of ol-mapbox-style omls.js. Since OpenLayers draws on the browser canvas, you also need to include the fonts used in the style in the page.

<!DOCTYPE html>
  <title>Klokantech Basic GL Style using ol-mapbox-style preview</title>
  <link rel="stylesheet" type="text/css" href="" />
  <link rel="stylesheet" href="[email protected]/ol.css">
    html, body {
      height: 100%;
      margin: 0;
    #map {
      width: 100%;
      height: 100%;
      background-color: #f8f4f0;
  <div id="map"></div>
  <script>var apiKey = 'insert_your_key_here'</script>
  <script src=",Promise"></script>
  <script src="[email protected]/dist/ol.js"></script>
  <script src="[email protected]/dist/olms.js"></script>
  <script src="ol.js"></script>


The code below uses ol-mapbox-style to fetch the GL style and turn it into an OpenLayers map. Once the map is configured, the promise of the olms function resolves, and any desired manipulations can be performed on the map.

In the following code, you have to replace “insert_your_key_here” with a key from hosting. You can get a free key at

olms.apply('map', '' + apiKey).then(function(map) {
  // do anything with the passed `ol.Map` instance here.
}); is an open-source project from OMT community and MapTiler who provides Maps API.
Read the documentation for map developers. Share this page on