Skip to content

Style

The Style base class

Extends

Methods

addLayer()

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

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

Parameter Type Description
layerObject AddLayerObject The style layer to add.
before? string ID of an existing layer to insert before
options? StyleSetterOptions Style setter options.

Returns

this

Source

src/style/style.ts:905


addSprite()

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

Add a sprite.

Parameters

Parameter Type Description
id string The id of the desired sprite
url string The url to load the desired sprite from
options StyleSetterOptions The style setter options
completion? (err: Error) => void The completion handler

Returns

void

Source

src/style/style.ts:1676


getFilter()

getFilter(layer: string): void | FilterSpecification

Get a layer's filter object

Parameters

Parameter Type Description
layer string the layer to inspect

Returns

void | FilterSpecification

the layer's filter, if any

Source

src/style/style.ts:1124


getLayer()

getLayer(id: string): StyleLayer

Return the style layer object with the given id.

Parameters

Parameter Type Description
id string id of the desired layer

Returns

StyleLayer

a layer, if one with the given id exists

Source

src/style/style.ts:1049


getLayersOrder()

getLayersOrder(): string[]

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

Returns

string[]

ids of layers, in order

Source

src/style/style.ts:1058


getLayoutProperty()

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

Get a layout property's value from a given layer

Parameters

Parameter Type Description
layerId string the layer to inspect
name string the name of the layout property

Returns

any

the property value

Source

src/style/style.ts:1149


getSource()

getSource(id: string): Source

Get a source by ID.

Parameters

Parameter Type Description
id string ID of the desired source

Returns

Source

source

Source

src/style/style.ts:894


getSprite()

getSprite(): object[]

Get the current sprite value.

Returns

object[]

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

Source

src/style/style.ts:1729


hasLayer()

hasLayer(id: string): boolean

Checks if a specific layer is present within the style.

Parameters

Parameter Type Description
id string the id of the desired layer

Returns

boolean

a boolean specifying if the given layer is present

Source

src/style/style.ts:1068


listens()

listens(type: string): boolean

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

Parameters

Parameter Type Description
type string The event type

Returns

boolean

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

Inherited from

Evented.listens

Source

src/util/evented.ts:161


moveLayer()

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

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

Parameter Type Description
id string ID of the layer to move
before? string ID of an existing layer to insert before

Returns

void

Source

src/style/style.ts:980


off()

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

Removes a previously registered event listener.

Parameters

Parameter Type Description
type string The event type to remove listeners for.
listener Listener The listener function to remove.

Returns

Style

Inherited from

Evented.off

Source

src/util/evented.ts:86


on()

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

Adds a listener to a specified event type.

Parameters

Parameter Type Description
type string The event type to add a listen for.
listener Listener The 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

this

Inherited from

Evented.on

Source

src/util/evented.ts:73


once()

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

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

Parameter Type Description
type string The event type to listen for.
listener? Listener The 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

Source

src/util/evented.ts:102


removeLayer()

removeLayer(id: string): void

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

Parameters

Parameter Type Description
id string id of the layer to remove

Returns

void

Source

src/style/style.ts:1013


removeSource()

removeSource(id: string): this

Remove a source from this stylesheet, given its id.

Parameters

Parameter Type Description
id string id of the source to remove

Returns

this

Throws

if no source is found with the given ID

Source

src/style/style.ts:852


removeSprite()

removeSprite(id: string): void

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

Parameter Type Description
id string the id of the sprite to remove

Returns

void

Source

src/style/style.ts:1697


setEventedParent()

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

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

Parameters

Parameter Type
parent? Evented
data? any

Returns

Style

Inherited from

Evented.setEventedParent

Source

src/util/evented.ts:172


setGeoJSONSourceData()

setGeoJSONSourceData(id: string, data: string | GeoJSON): void

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

Parameters

Parameter Type Description
id string id of the source
data string | GeoJSON GeoJSON source

Returns

void

Source

src/style/style.ts:878


setSprite()

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

Set a new value for the style's sprite.

Parameters

Parameter Type Description
sprite SpriteSpecification new sprite value
options StyleSetterOptions style setter options
completion? (err: Error) => void the completion handler

Returns

void

Source

src/style/style.ts:1740


setState()

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

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

Parameter Type
nextState StyleSpecification
options StyleSwapOptions & StyleSetterOptions

Returns

boolean

true if any changes were made; false otherwise

Source

src/style/style.ts:685