Sprite | Mapbox Style Spec | Mapbox Docs (original) (raw)

Search Style Specification

On this page

Additional Developer Resources

A sprite is a single image that contains all the icon and pattern images included in a style.

When a sprite is associated with a style, its images can be used to render the following style properties: background-pattern, fill-pattern, line-pattern, fill-extrusion-pattern and icon-image.

To use a sprite, a style must have a sprite property with a URL template as its value. For example:

Mapbox APIs and SDKs will use this URL template to request the two sprite files required to render icons and patterns on your map. You can read more about loading sprite files below.

Sprite files

A valid sprite source must supply two types of files: index files and image files.

Index file

A sprite's index file is a JSON document containing a description of each image contained in the sprite. The content of this file must be a JSON object whose keys form identifiers to be used as the values of the above style properties, and whose values are objects describing the dimensions (width and height properties) and pixel ratio (pixelRatio) of each individual image and its location within the sprite (x and y).

For example, a sprite containing a single image might have the following index file contents:

Given this data in the sprite index file, a style could refer to the image in this sprite image by creating a symbol layer with the layout property "icon-image": "poi", or with the tokenized value "icon-image": "{icon}" and vector tile features with an icon property with the value poi.

Apart from the required properties width, height, x, y, and pixelRatio, the following optional properties are supported:

For example, you could use these optional parameters to define a highway shield image with specified bounds for label text and stretchable zones that help decrease distortion when the shield is rendered on a map at a size larger than its original size in the sprite image file:

In the example above, the illustration shows the content area with a black dotted line (), and shows the stretchX and stretchY zones with pink () and yellow () color highlighting.

Image file

A sprite's image file is a PNG image containing the sprite data.

The maximum size of a sprite is bounded by WebGL MAX_TEXTURE_SIZE, which depends on a client's GPU, but is usually at least 4096×4096 pixels.

You can see an example of a sprite image file on this sprite glossary entry.

Creating sprite files

You can create sprite files in two ways:

Loading sprite files

Mapbox APIs and SDKs will use the value of the sprite property in the style as a URL template to generate complete URLs for both sprite files:

For example, if you specified "sprite": "https://example.com/sprite" in your style, renderers would load either:

Additional Developer Resources