Edit

Mapbox Vector Layer

mapbox5 studio1 vector69 tiles6

Rendering a layer with a Mapbox-hosted style.

The MapboxVector layer allows you to create a layer based on a Mapbox-hosted style using a single vector source. If your style uses more than one source, use the source property to choose a single vector source. Use the layers property if you only want to render a subset of the style's layers (provided they all share the same source).

main.js
import 'ol/ol.css';
import Map from 'ol/Map';
import MapboxVector from 'ol/layer/MapboxVector';
import View from 'ol/View';

const map = new Map({
  target: 'map',
  layers: [
    new MapboxVector({
      styleUrl: 'mapbox://styles/mapbox/bright-v9',
      accessToken:
        'Your Mapbox access token from https://mapbox.com/ here',
    }),
  ],
  view: new View({
    center: [0, 0],
    zoom: 2,
  }),
});
index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Mapbox Vector Layer</title>
    <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
    <script src="https://unpkg.com/elm-pep@1.0.6/dist/elm-pep.js"></script>
    <!-- The lines below are only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v3/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,TextDecoder"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/3.18.3/minified.js"></script>
    <style>
      .map {
        width: 100%;
        height:400px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script src="main.js"></script>
  </body>
</html>
package.json
{
  "name": "mapbox-vector-layer",
  "dependencies": {
    "ol": "6.13.1-dev"
  },
  "devDependencies": {
    "parcel": "^2.0.0"
  },
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build --public-url . index.html"
  }
}