Class: TextureStore

TextureStore(source, stage, opts)

A TextureStore maintains a cache of textures used to render a Layer.

A Stage communicates with the TextureStore through the startFrame(), markTile() and endFrame() methods, which indicate the tiles that are visible in the current frame. Textures for visible tiles are loaded and retained as long as the tiles remain visible. A limited amount of textures whose tiles were previously visible are cached according to an LRU policy. Tiles may be pinned to keep their respective textures cached even when they are invisible; these textures do not count towards the previously visible limit.

Multiple layers belonging to the same underlying WebGlStage may share the same TextureStore. Layers belonging to distinct WebGlStage instances may not do so due to restrictions on the use of textures across stages.

Constructor

new TextureStore(source, stage, opts)

Parameters:
Name Type Description
source Source

The underlying source.

stage Stage

The underlying stage.

opts Object

Options.

Properties
Name Type Attributes Default Description
previouslyVisibleCacheSize Number <optional>
32

The maximum number of previously visible textures to cache according to an LRU policy.

Methods

clear()

Remove all textures from the TextureStore, including pinned textures.

clearNotPinned()

Remove all textures in the TextureStore, excluding unpinned textures.

destroy()

Destructor.

endFrame()

Signal the end of a frame. Called from Stage.

markTile(tile)

Mark a tile as visible within the current frame. Called from Stage.

Parameters:
Name Type Description
tile Tile

The tile to mark.

pin(tile) → {number}

Pin a tile. Textures for pinned tiles are never evicted from the store. Upon pinning, the texture is created if not already present. Pins are reference-counted; a tile may be pinned multiple times and must be unpinned the corresponding number of times. Pinning is useful e.g. to ensure that the lowest-resolution level of an image is always available to fall back onto.

Parameters:
Name Type Description
tile Tile

the tile to pin

Returns:

the pin reference count.

Type
number

query(tile) → {TileState}

Return the state of a tile.

Parameters:
Name Type Description
tile Tile

The tile to query.

Returns:
Type
TileState

source() → {Source}

Return the underlying Source.

Returns:
Type
Source

stage() → {Stage}

Return the underlying Stage.

Returns:
Type
Stage

startFrame()

Signal the beginning of a frame. Called from Stage.

unpin(tile) → {number}

Unpin a tile. Pins are reference-counted; a tile may be pinned multiple times and must be unpinned the corresponding number of times.

Parameters:
Name Type Description
tile Tile

the tile to unpin

Returns:

the pin reference count.

Type
number

Events

textureCancel

Signals that loading a texture has been cancelled.

This event may follow TextureStore#textureStartLoad if the texture becomes unnecessary before it finishes loading.

Parameters:
Name Type Description
tile Tile

The tile for which the texture loading was cancelled.

textureError

Signals that loading a texture has failed.

This event may follow TextureStore#textureStartLoad if the texture fails to load.

Parameters:
Name Type Description
tile Tile

The tile for which the texture loading has failed.

textureInvalid

Signals that a texture has been invalidated.

This event may be raised for a texture with an underlying dynamic asset. It may only occur while the texture is loaded, i.e., in between TextureStore#textureLoad and TextureStore#textureUnload.

Parameters:
Name Type Description
tile Tile

The tile for which the texture was invalidated.

textureLoad

Signals that a texture has been loaded.

Parameters:
Name Type Description
tile Tile

The tile for which the texture was loaded.

textureStartLoad

Signals that a texture has started to load.

This event is followed by either TextureStore#textureLoad, TextureStore#textureError or TextureStore#textureCancel.

Parameters:
Name Type Description
tile Tile

The tile for which the texture has started to load.

textureUnload

Signals that a texture has been unloaded.

Parameters:
Name Type Description
tile Tile

The tile for which the texture was unloaded.