For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Interface StyleImageInterface
data:
| Uint8Array<ArrayBufferLike>
| Uint8ClampedArray<ArrayBufferLike>
| StyleImageWebGLData;
height: number;
onAdd?: (map: MapMLGL, id: string) => void;
onRemove?: () => void;
render?: () => boolean;
width: number;
}
Properties
data
The image's pixels, in the same format as ImageData, or a StyleImageWebGLData
callback that renders them with WebGL. A WebGL image renders straight into its slot of the
shared icon atlas. Nothing new is possible that pixels could not express, but an image that
changes often, such as an animated icon, gets much cheaper: no CPU pixel work and no upload.
height
OptionalonAdd
Optional method called when the layer has been added to the Map with Map.addImage.
OptionalonRemove
Optional method called when the icon is removed from the map with Map.removeImage. This gives the image a chance to clean up resources and event listeners.
This also fires when the WebGL context is lost, after which the same image is added back
without a matching onAdd, so the image has to be able to build again whatever it
released here.
Optionalrender
This method is called once before every frame where the icon will be used.
The method can optionally update the image's data member with a new image.
If the method updates the image it must return true to commit the change.
If the method returns false or nothing the image is assumed to not have changed.
An animated image schedules its next frame by calling Map.triggerRepaint, typically
from a timer; returning false in between lets the map rest and fire idle.
An image whose data renders with WebGL has nothing to update here; returning true is how
it asks for StyleImageWebGLData.renderWithWebGL to be called again.
If updates are infrequent it maybe easier to use Map.updateImage to update the image instead of implementing this method.
Type Declaration
- (): boolean
Returns boolean
trueif this method updated the image.falseif the image was not changed.
Interface for dynamically generated style images. This is a specification for implementers to model: it is not an exported method or class.
Images implementing this interface can be redrawn for every frame. They can be used to animate icons and patterns or make them respond to user input. Style images can implement a StyleImageInterface.render method. The method is called every frame and can be used to update the image.
See
Add an animated icon to the map.
Example