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
Hierarchy (View Summary)
- Evented<ImageManagerEventType>
- ImageManager
Index
Constructors
Properties
Methods
Constructors
constructor
Returns ImageManager
Properties
images
loaded
missingImageResolver
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
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
addImage
Parameters
- id: string
- image: StyleImage
Returns void
beginFrame
Returns void
cloneImages
Returns Record<string, StyleImage>
destroy
Returns void
dispatchRenderCallbacks
Re-renders the images among
idsthat were added with arendercallback (seeStyleImageInterface), at most once per frame each.Parameters
- ids: string[]
Returns void
fire
Calls every listener registered for the event's type.
Parameters
- event: ErrorEvent | MapStyleImageMissingEvent
Returns this
Compatibility with the (type: string, properties: Object) signature from previous versions. See https://github.com/mapbox/mapbox-gl-js/issues/6522, https://github.com/mapbox/mapbox-gl-draw/issues/766
Parameters
- type: keyof ImageManagerEventType
Optionalproperties: object
Returns this
getImage
Parameters
- id: string
Returns StyleImage
getImages
Parameters
- ids: string[]
Returns Promise<GetImagesResponse>
isLoaded
Returns boolean
listens
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
Parameters
- type: keyof ImageManagerEventType
The event type
Returns boolean
trueif there is at least one registered listener for specified event type,falseotherwise- type: keyof ImageManagerEventType
listImages
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.
off
- off<T extends keyof ImageManagerEventType>(
type: T,
listener: (event: ImageManagerEventType[T]) => void,
): thisRemoves a previously registered event listener.
Type Parameters
- T extends keyof ImageManagerEventType
Parameters
- type: T
The event type to remove listeners for.
- listener: (event: ImageManagerEventType[T]) => void
The listener function to remove.
Returns this
on
- on<T extends keyof ImageManagerEventType>(
type: T,
listener: (event: ImageManagerEventType[T]) => void,
): SubscriptionAdds a listener to a specified event type.
Type Parameters
- T extends keyof ImageManagerEventType
Parameters
- type: T
The event type to add a listen for.
- listener: (event: ImageManagerEventType[T]) => void
The function to be called when the event is fired. The listener function is called with the data object passed to
fire, extended withtargetandtypeproperties.
Returns Subscription
once
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
- T extends keyof ImageManagerEventType
Parameters
- type: T
The event type to listen for.
Returns Promise<ImageManagerEventType[T]>
a promise that resolves with the event
- once<T extends keyof ImageManagerEventType>(
type: T,
listener: (event: ImageManagerEventType[T]) => void,
): thisAdds 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
- T extends keyof ImageManagerEventType
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
thiswhen a listener is provided
removeAllSpriteImages
Removes the images of every sprite, leaving the images added at runtime alone.
Returns string[]
the ids of the removed images
removeImage
Parameters
- id: string
Returns void
removeSpriteImages
Removes all the images a single sprite has brought in.
Parameters
- spriteId: string
Returns string[]
the ids of the removed images
setEventedParent
- setEventedParent(
parent?: Evented<EventTypeMap> | null,
data?: EventedParentData | (() => EventedParentData),
): thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
Optionalparent: Evented<EventTypeMap> | nullOptionaldata: EventedParentData | (() => EventedParentData)
Returns this
setLoaded
Parameters
- loaded: boolean
Returns void
setMissingImageResolver
Parameters
- resolver: MissingImageRequestHandler | null
Returns void
setSpriteImages
- setSpriteImages(
spriteId: string,
images: Record<string, StyleImage>,
): { loaded: string[]; removed: string[] }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
- spriteId: string
updateImage
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: booleanwhether to reject an image of a different size than the one it replaces
Returns void
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.