For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.

Class ImageManager

Owns every image of the style - the ones the sprites bring in as well as the ones added at runtime - and tracks requests for them from the tile workers, sending responses when the requests are fulfilled.

Hierarchy (View Summary)

Index

Constructors

Properties

images: Record<string, StyleImage>
loaded: boolean
missingImageResolver: MissingImageRequestHandler | null
requestors: {
    ids: string[];
    promiseResolve: (
        value: GetImagesResponse | PromiseLike<GetImagesResponse>,
    ) => void;
}[]

This is used to track requests for images that are not yet available. When the image is loaded, the requestors will be notified.

updateVersion: number

Incremented on every ImageManager.updateImage call. ImageAtlas instances compare it against the value they last patched against, so that a tile whose atlas is up to date can skip its patching work entirely.

Methods

  • Returns void

  • Returns void

  • Re-renders the images among ids that were added with a render callback (see StyleImageInterface), at most once per frame each.

    Parameters

    • ids: string[]

    Returns void

  • Returns boolean

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

    Parameters

    Returns boolean

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

  • Returns string[]

    the ids of every image currently held, sprite images and runtime ones alike. The returned array is shared between callers and must not be modified.

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

    Type Parameters

    Parameters

    • type: T

      The event type to listen for.

    Returns Promise<ImageManagerEventType[T]>

    a promise that resolves with the event

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

    Type Parameters

    Parameters

    • type: T

      The event type to listen for.

    • listener: (event: ImageManagerEventType[T]) => void

      The function to be called when the event is fired the first time.

    Returns this

    this when a listener is provided

  • Removes the images of every sprite, leaving the images added at runtime alone.

    Returns string[]

    the ids of the removed images

  • Parameters

    • id: string

    Returns void

  • Removes all the images a single sprite has brought in.

    Parameters

    • spriteId: string

    Returns string[]

    the ids of the removed images

  • Parameters

    • loaded: boolean

    Returns void

  • Takes over the images of a single sprite: adds the new ones, updates the ones that are already known, and removes the ones that a previous load of this same sprite had brought in but that are not part of it anymore.

    Parameters

    • spriteId: string

      the id of the sprite the images belong to

    • images: Record<string, StyleImage>

      the sprite's images, keyed by their id within the sprite

    Returns { loaded: string[]; removed: string[] }

    the ids of the images that this sprite now provides, and the ids of the ones that were removed because they are no longer part of it

  • Replaces an image that is already known under this id, bumping its version so that the atlases holding it notice.

    The old record is read directly rather than through ImageManager.getImage, which would force a synchronous decode of the sprite data of the very image being replaced. Its size therefore comes from whichever of the two the pixels are still in, since an image that came from a sprite and was never rendered has not been decoded yet, and its version is defaulted, since images start out without one.

    Parameters

    • id: string
    • image: StyleImage
    • Optionalvalidate: boolean

      whether to reject an image of a different size than the one it replaces

    Returns void

Was this helpful?