Class Style

The Style base class

Hierarchy (view full)

Methods

  • 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

    • layerObject: AddLayerObject

      The style layer to add.

    • Optional before: string

      ID of an existing layer to insert before

    • options: StyleSetterOptions = {}

      Style setter options.

    Returns this

  • Add a sprite.

    Parameters

    • id: string

      The id of the desired sprite

    • url: string

      The url to load the desired sprite from

    • options: StyleSetterOptions = {}

      The style setter options

    • Optional completion: ((err) => void)

      The completion handler

        • (err): void
        • Parameters

          • err: Error

          Returns void

    Returns void

  • Get a layer's filter object

    Parameters

    • layer: string

      the layer to inspect

    Returns void | FilterSpecification

    the layer's filter, if any

  • Return the style layer object with the given id.

    Parameters

    • id: string

      id of the desired layer

    Returns StyleLayer

    a layer, if one with the given id exists

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

    Returns string[]

    ids of layers, in order

  • Get a layout property's value from a given layer

    Parameters

    • layerId: string

      the layer to inspect

    • name: string

      the name of the layout property

    Returns any

    the property value

  • Get a source by ID.

    Parameters

    • id: string

      ID of the desired source

    Returns Source

    source

  • Get the current sprite value.

    Returns {
        id: string;
        url: string;
    }[]

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

  • Checks if a specific layer is present within the style.

    Parameters

    • id: string

      the id of the desired layer

    Returns boolean

    a boolean specifying if the given layer is present

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

    Parameters

    • type: string

      The event type

    Returns boolean

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

  • 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

    • id: string

      ID of the layer to move

    • Optional before: string

      ID of an existing layer to insert before

    Returns void

  • Removes a previously registered event listener.

    Parameters

    • type: string

      The event type to remove listeners for.

    • listener: Listener

      The listener function to remove.

    Returns Style

  • Adds a listener to a specified event type.

    Parameters

    • 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

  • 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

    • type: string

      The event type to listen for.

    • Optional 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

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

    Parameters

    • id: string

      id of the layer to remove

    Returns void

  • Remove a source from this stylesheet, given its id.

    Parameters

    • id: string

      id of the source to remove

    Returns this

    Throws

    if no source is found with the given ID

  • 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

    • id: string

      the id of the sprite to remove

    Returns void

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

    Parameters

    • Optional parent: Evented
    • Optional data: any

    Returns Style

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

    Parameters

    • id: string

      id of the source

    • data: string | GeoJSON

      GeoJSON source

    Returns void

  • Set a new value for the style's sprite.

    Parameters

    • sprite: SpriteSpecification

      new sprite value

    • options: StyleSetterOptions = {}

      style setter options

    • Optional completion: ((err) => void)

      the completion handler

        • (err): void
        • Parameters

          • err: Error

          Returns void

    Returns void

  • 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

    Returns boolean

    true if any changes were made; false otherwise