Chevron DownAPI Reference

Use layers as custom Mapbox layers, enabling seamless interleaving of Mapbox and layers.

Advantages and Limitations


  • Mapbox and layers can be freely "interleaved", enabling a number of layer mixing effects, such as drawing behind map labels, z-occlusion between 3D objects and Mapbox buildings, etc.
  • Mapbox and will share a single canvas and WebGL context, saving system resources.


  •'s multi-view system cannot be used.
  • Unless used with react-map-gl, WebGL2 based features, such as attribute transitions and GPU accelerated aggregation layers cannot be used.


Include the Standalone Bundle

<script src="^8.1.0/dist.min.js"></script>
<script src=''></script>
<script type="text/javascript">
  const {MapboxLayer} = deck;

Install from NPM

npm install
import {MapboxLayer} from '';


Using with Pure JS

To create a Mapbox-compatible layer:

import {ScatterplotLayer} from '';
import {MapboxLayer} from '';

const myDeckLayer = new MapboxLayer({
  id: 'my-scatterplot',
  type: ScatterplotLayer,
  data: [
    {position: [-74.5, 40], size: 100}
  getPosition: d => d.position,
  getRadius: d => d.size,
  getColor: [255, 0, 0]

To add the layer to Mapbox:

import mapboxgl from 'mapbox-gl';

mapboxgl.accessToken = '<your access token here>';
const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v9',
  center: [-74.50, 40],
  zoom: 9

map.on('load', () => {

Using with React

import React, {useState, useRef, useCallback} from 'react';
import DeckGL from '';
import {ScatterplotLayer} from '';
import {StaticMap} from 'react-map-gl';

import {MapboxLayer} from '';

  longitude: -74.50,
  latitude: 40,
  zoom: 9

const data = [
  {position: [-74.5, 40], size: 100}

function App() {
  // DeckGL and mapbox will both draw into this WebGL context
  const [glContext, setGLContext] = useState();
  const deckRef = useRef(null);
  const mapRef = useRef(null);

  const onMapLoad = useCallback(() => {
    const map = mapRef.current.getMap();
    const deck = deckRef.current.deck;

    // You must initialize an empty layer to prevent flashing
      // This id has to match the id of the layer
      new MapboxLayer({ id: "my-scatterplot", deck }),
      // Optionally define id from Mapbox layer stack under which to add deck layer
  }, []);

  const layers = [
    new ScatterplotLayer({
      id: 'my-scatterplot',
      getPosition: d => d.position,
      getRadius: d => d.size,
      getFillColor: [255, 0, 0]

  return (
        /* To render vector tile polygons correctly */
        stencil: true
      {glContext && (
        /* This is important: Mapbox must be instantiated after the WebGLContext is available */

Injecting Layers into Mapbox

Adding a 3D deck layer

In this cases, the application wants to add a 3D layer (e.g. ArcLayer, HexagonLayer, GeoJsonLayer) on top of a Mapbox basemap, while seamlessly blend into the z-buffer. This will interleave the useful visualization layers from both the and Mapbox layer catalogs. In this case, the Mapbox map.addLayer(layer) API method can be used to add a mix of and Mapbox layers to the top of the layer stack from the currently loaded Mapbox style.

Inserting a 2D deck layer before an existing Mapbox layer

One major use case for mixing and Mapbox layers is that some important information in the Mapbox map is hidden by a visualization layer, and controlling opacity is not enough. A typical example of this is labels and roads, where it is desirable to have a visualization layer render on top of the Mapbox geography, but where one might still want to see e.g. labels and/or roads. Alternatively, the visualization should cover the ground, but not the roads and labels.

A bit more control is provided by the optional before parameter of the Mapbox map.addLayer(layer, before?) API. Using this parameter, it is possible to inject a MapboxLayer instance just before any existing Mapbox layer in the layer stack of the currently loaded style.

Mapbox provides an example of finding the first label layer. For more sophisticated injection point lookups, refer to Mapbox' documentation on the format of Mapbox style layers, see Mapbox Style Spec.