Skip to content

[RFC] New feature: Images in labels #8604

Description

@alexshalamov

Images inside text-field

This RFC explores possibility of embedding images within a text defined by symbol layer's text-field property.

Style interface

Images within a text could be added via new image expression that takes one mandatory argument that must evaluate to string, for example ["image", "car-15"].

Within 'format' expression, optional image options object may be provided after 'image' expression. Image options properties could be:

  • height - sets height of an image
  • width - sets width of an image
  • scale - proportional scaling
  • color - applicable for SDF icons
  • sources - array of sources from where image would be tried to be fetched, like <img src=[url1, url2...]> (spritesheet, base url, etc). Example:
    ["spritesheet://icons", "https://www.mapbox.com/images/"]

Support for aforementioned image option properties may be added in the future if found useful.

Example syntax

The new image expression can be used as a section within text-field’s format expression, for instance:

"icon-image": "philadelphia-septa",
"text-field": ["format", 
                    "London ",
                    ["image", "gb-national-rail.london-tfl-rail.london-underground"],
                    " and Taipei ",
                    ["image", "taipei-metro"], { "useful": "image option" } 
                    " metro\n",
                    "SF ", {"text-color": "blue"},
                    ["image", "san-francisco-bart"],
                    " bart"
]

The new image expression could be represented by Image object ('coercable' to string if needed). The Image object would contain image id and image options. If needed, "icon-image" property could be converted to accept "image" expression, so that the text-field and icon-image properties would benefit from new functionality.

"icon-image": ["image", "philadelphia-septa"]

Rendering result

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions