Skip to content

Both copy text to your clipboard — Build with AI copies a setup prompt to paste into Claude Code, Cursor, Codex or Copilot; Copy page as Markdown copies this page to paste into a chat. How it works

Style ​

Defined in: src/style/style.ts:201

The Style base class

Extends ​

Methods ​

_findGlobalStateAffectedSources() ​

_findGlobalStateAffectedSources(globalStateRefs: string[]): Set<string>

Defined in: src/style/style.ts:362

Find all sources that are affected by the global state changes. For example, if a layer filter uses global-state expression, this function will return the source id of that layer.

Parameters ​

ParameterType
globalStateRefsstring[]

Returns ​

Set<string>


addLayer() ​

addLayer(layerObject: AddLayerObject, before?: string, options?: StyleSetterOptions): this

Defined in: src/style/style.ts:1035

Add a layer to the map style. The layer will be inserted before the layer with ID before, or appended if before is omitted.

Parameters ​

ParameterTypeDescription
layerObjectAddLayerObjectThe style layer to add.
before?stringID of an existing layer to insert before
options?StyleSetterOptionsStyle setter options.

Returns ​

this


addSprite() ​

addSprite(id: string, url: string, options: StyleSetterOptions, completion?: (err: Error) => void): void

Defined in: src/style/style.ts:1881

Add a sprite.

Parameters ​

ParameterTypeDescription
idstringThe id of the desired sprite
urlstringThe url to load the desired sprite from
optionsStyleSetterOptionsThe style setter options
completion?(err: Error) => voidThe completion handler

Returns ​

void


getFilter() ​

getFilter(layer: string): void | FilterSpecification

Defined in: src/style/style.ts:1254

Get a layer's filter object

Parameters ​

ParameterTypeDescription
layerstringthe layer to inspect

Returns ​

void | FilterSpecification

the layer's filter, if any


getLayer() ​

getLayer(id: string): StyleLayer

Defined in: src/style/style.ts:1179

Return the style layer object with the given id.

Parameters ​

ParameterTypeDescription
idstringid of the desired layer

Returns ​

StyleLayer

a layer, if one with the given id exists


getLayersOrder() ​

getLayersOrder(): string[]

Defined in: src/style/style.ts:1188

Return the ids of all layers currently in the style, including custom layers, in order.

Returns ​

string[]

ids of layers, in order


getLayoutProperty() ​

getLayoutProperty(layerId: string, name: string): any

Defined in: src/style/style.ts:1279

Get a layout property's value from a given layer

Parameters ​

ParameterTypeDescription
layerIdstringthe layer to inspect
namestringthe name of the layout property

Returns ​

any

the property value


getSource() ​

getSource(id: string): Source

Defined in: src/style/style.ts:1024

Get a source by ID.

Parameters ​

ParameterTypeDescription
idstringID of the desired source

Returns ​

Source

source


getSprite() ​

getSprite(): object[]

Defined in: src/style/style.ts:1934

Get the current sprite value.

Returns ​

object[]

empty array when no sprite is set; id-url pairs otherwise


hasLayer() ​

hasLayer(id: string): boolean

Defined in: src/style/style.ts:1198

Checks if a specific layer is present within the style.

Parameters ​

ParameterTypeDescription
idstringthe id of the desired layer

Returns ​

boolean

a boolean specifying if the given layer is present


listens() ​

listens(type: string): boolean

Defined in: src/util/evented.ts:165

Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.

Parameters ​

ParameterTypeDescription
typestringThe event type

Returns ​

boolean

true if there is at least one registered listener for specified event type, false otherwise

Inherited from ​

Evented.listens


moveLayer() ​

moveLayer(id: string, before?: string): void

Defined in: src/style/style.ts:1110

Moves a layer to a different z-position. The layer will be inserted before the layer with ID before, or appended if before is omitted.

Parameters ​

ParameterTypeDescription
idstringID of the layer to move
before?stringID of an existing layer to insert before

Returns ​

void


off() ​

off(type: string, listener: Listener): Style

Defined in: src/util/evented.ts:90

Removes a previously registered event listener.

Parameters ​

ParameterTypeDescription
typestringThe event type to remove listeners for.
listenerListenerThe listener function to remove.

Returns ​

Style

Inherited from ​

Evented.off


on() ​

on(type: string, listener: Listener): Subscription

Defined in: src/util/evented.ts:73

Adds a listener to a specified event type.

Parameters ​

ParameterTypeDescription
typestringThe event type to add a listen for.
listenerListenerThe function to be called when the event is fired. The listener function is called with the data object passed to fire, extended with target and type properties.

Returns ​

Subscription

Inherited from ​

Evented.on


once() ​

once(type: string, listener?: Listener): Promise<any> | Style

Defined in: src/util/evented.ts:106

Adds a listener that will be called only once to a specified event type.

The listener will be called first time the event fires after the listener is registered.

Parameters ​

ParameterTypeDescription
typestringThe event type to listen for.
listener?ListenerThe function to be called when the event is fired the first time.

Returns ​

Promise<any> | Style

this or a promise if a listener is not provided

Inherited from ​

Evented.once


removeLayer() ​

removeLayer(id: string): void

Defined in: src/style/style.ts:1143

Remove the layer with the given id from the style. A ErrorEvent event will be fired if no such layer exists.

Parameters ​

ParameterTypeDescription
idstringid of the layer to remove

Returns ​

void


removeSource() ​

removeSource(id: string): this

Defined in: src/style/style.ts:982

Remove a source from this stylesheet, given its id.

Parameters ​

ParameterTypeDescription
idstringid of the source to remove

Returns ​

this

Throws ​

if no source is found with the given ID


removeSprite() ​

removeSprite(id: string): void

Defined in: src/style/style.ts:1902

Remove a sprite by its id. When the last sprite is removed, the whole this.stylesheet.sprite object becomes undefined. This falsy undefined value later prevents attempts to load the sprite when it's absent.

Parameters ​

ParameterTypeDescription
idstringthe id of the sprite to remove

Returns ​

void


setEventedParent() ​

setEventedParent(parent?: Evented, data?: any): Style

Defined in: src/util/evented.ts:176

Bubble all events fired by this instance of Evented to this parent instance of Evented.

Parameters ​

ParameterType
parent?Evented
data?any

Returns ​

Style

Inherited from ​

Evented.setEventedParent


setGeoJSONSourceData() ​

setGeoJSONSourceData(id: string, data: string | GeoJSON<Geometry, {[name: string]: any; }>): void

Defined in: src/style/style.ts:1008

Set the data of a GeoJSON source, given its id.

Parameters ​

ParameterTypeDescription
idstringid of the source
datastring | GeoJSON<Geometry, {[name: string]: any; }>GeoJSON source

Returns ​

void


setSprite() ​

setSprite(sprite: SpriteSpecification, options: StyleSetterOptions, completion?: (err: Error) => void): void

Defined in: src/style/style.ts:1945

Set a new value for the style's sprite.

Parameters ​

ParameterTypeDescription
spriteSpriteSpecificationnew sprite value
optionsStyleSetterOptionsstyle setter options
completion?(err: Error) => voidthe completion handler

Returns ​

void


setState() ​

setState(nextState: StyleSpecification, options: StyleSwapOptions & StyleSetterOptions): boolean

Defined in: src/style/style.ts:805

Update this style's state to match the given style JSON, performing only the necessary mutations.

May throw an Error ('Unimplemented: METHOD') if the mapbox-gl-style-spec diff algorithm produces an operation that is not supported.

Parameters ​

ParameterType
nextStateStyleSpecification
optionsStyleSwapOptions & StyleSetterOptions

Returns ​

boolean

true if any changes were made; false otherwise