addLayer method

MapboxMap addLayer(
  1. dynamic layer, [
  2. String? beforeId
])

Adds a Mapbox style layer to the map's style.

A layer defines how data from a specified source will be styled. Read more about layer types and available paint and layout properties in the Mapbox Style Specification.

@param {Object | CustomLayerInterface} layer The style layer to add, conforming to the Mapbox Style Specification's layer definition. @param {string} beforeId The ID of an existing layer to insert the new layer before. If this argument is omitted, the layer will be appended to the end of the layers array.

@returns {MapboxMap} this

@example // Add a circle layer with a vector source. map.addLayer({ id: 'points-of-interest', source: { type: 'vector', url: 'mapbox://mapbox.mapbox-streets-v8' }, 'source-layer': 'poi_label', type: 'circle', paint: { // Mapbox Style Specification paint properties }, layout: { // Mapbox Style Specification layout properties } });

@see Create and style clusters @see Add a vector tile source @see Add a WMS source

Implementation

MapboxMap addLayer(dynamic layer, [String? beforeId]) {
  if (layer is Layer) {
    return MapboxMap.fromJsObject(
        jsObject.addLayer(layer.jsObject, beforeId));
  }
  return MapboxMap.fromJsObject(jsObject.addLayer(jsify(layer), beforeId));
}