Layers

A style's layers property lists all the layers available in that style.

setLayer

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

map.setLayer(layer, beforlayerID);

Parameter

Required ParameterDescriptionType

id

A unique identifier that you define.

String

source

The data source for the layer. Reference a source that has already been defined using the source's unique id.

String

type

The type of layer (ex. fill or symbol)

A list of layer types is available in the Style Specification

String

Optional ParameterDescriptionType

filter

An expression specifying conditions on source features. Only features that match the filter are displayed.

Array

minzoom

The minimum zoom level for the layer.

number

maxzoom

The maximum zoom level for the layer.

number

layout

Layout properties for the layer. Available layout properties vary by layer.type . A full list of layout properties for each layer type is available in the Style Specification

Object

paint

Paint properties for the layer. Available paint properties vary by layer.type .

A full list of paint properties for each layer type is available in the Style Specification

Object

beforlayerID

The ID of an existing layer to insert the new layer before, resulting in the new layer appearing visually beneath the existing layer.

String

Example

map.addLayer({
    id: 'some Layer ID',
    // References the GeoJSON source defined above
    // and does not require a `source-layer`
    source: 'some Source ID',
    //Style Specification
    type: 'symbol',
    layout: {
        // Set the label content to the
        // feature's `name` property
        'text-field': ['get', 'name'] //or String
    }
    paint: {
        'text-color' : '#000000'
    }
});

moveLayer

Moves a layer to a different z-position.

map.moveLayer(id, beforlayerID)

Parameter

Required ParameterDescriptionType

id

The ID of the layer to move.

String

beforlayerID

The ID of an existing layer to insert the new layer before. When viewing the map, the id layer will appear beneath the beforeId layer.

String

Example

map.moveLayer('3d_building-kor', 'landuse');

removeLayer

Removes the layer with the given ID from the map's style.

map.removeLayer(id);

Parameter

Required ParameterDescriptionType

id

ID of the layer to remove.

String

Example

if (map.getLayer('3d_building-kor')) map.removeLayer('3d_building-kor');

getLayer

Returns the layer with the specified ID in the map's style.

map.getLayer(id);

Parameter

Required ParameterDescriptionType

id

The ID of the layer to get.

String

Example

const stateDataLayer = map.getLayer('3d_building-kor');

setFilter

Sets the filter for the specified style layer.

map.setFilter(layerId, filter);

Parameter

Required ParameterDescriptionType

layerId

The ID of the layer to which the filter will be applied.

String

filter

Filters control which features a style layer renders from its source.

Array | null

Example

// display only features with the 'name' property 'USA'
map.setFilter('my-layer', ['==', ['get', 'name'], 'USA']);
// remove the filter for the 'my-layer' style layer
map.setFilter('my-layer', null);

getFilter

Returns the filter applied to the specified style layer.

map.getFilter(layerId);

Parameter

Required ParameterDescriptionType

layerId

The ID of the style layer whose filter to get.

String

Example

const filter = map.getFilter('myLayer');

setPaintProperty

Returns the filter applied to the specified style layer.

map.setPaintProperty(layerId, name, value);

Parameter

Required ParameterDescriptionType

layerId

The ID of the layer to set the paint property in.

String

name

The name of the paint property to set.

String

value

The value of the paint property to set. Must be of a type appropriate for the property

any

Example

map.setPaintProperty('my-layer', 'fill-color', '#faafee');

getPaintProperty

Returns the value of a paint property in the specified style layer.

map.getPaintProperty(layerId, name);

Parameter

Required ParameterDescriptionType

layerId

The ID of the layer to get the paint property from.

String

name

The name of the paint property to set.

String

Example

const paintProperty = map.getPaintProperty('mySymbolLayer', 'icon-color');

setLayoutProperty

Sets the value of a layout property in the specified style layer.

map.setLayoutProperty(layerId, name, value);

Parameter

Required ParameterDescriptionType

layerId

The ID of the layer to set the layout property in.

String

name

The name of the layout property to set.

String

value

The value of the layout property. Must be of a type appropriate for the property

any

Example

map.setLayoutProperty('my-layer', 'visibility', 'none');

getLayoutProperty

Returns the value of a layout property in the specified style layer.

map.getLayoutProperty(layerId, name);

Parameter

Required ParameterDescriptionType

layerId

TThe ID of the layer to get the layout property from.

String

name

The name of the layout property to get.

String

Example

const layoutProperty = map.getLayoutProperty('mySymbolLayer', 'icon-anchor');

Last updated