Skip to content

Support multi-icon symbols #4366

Open
Open

Description

@indus

Motivation

I want to show a complex set of icons: ~100 basetypes with ~30 modifiers. There is no way to predefine ~3000 icons in the PNG sprite and then just pick the right one. I want to define ~130 and combine them freely. That already works by using two independent layers, but then "basetypes" and "modifiers" are on different z-indices so they interfere with each other.

Design Alternatives

Design 1: make "icon-image" accept an array (has to be implemented on other "icon-" options like "icon-offset" as well)

...
"icon-image": ["{basetype}", "{modifier}"]
...

Design 1a : don´t use an array on every single property but shift it up the to the "paint" and "layout" property.

Design 2: allow the definition of combined icons in the sprite JSON

...
"basetype":{"x":0,"y":0,"width":20,"height":40,"pixelRatio":1},
"modifier":{"x":20,"y":0,"width":20,"height":20,"pixelRatio":1},
"combined":{"icons":["basetype","modifier"], "offset":[[0,0],[0,20]]}
...

Design

Advantages Design 1: dynamic styling
Drawbacks Design 1: complex due to multiplication of icon-properties by number of icons

Advantages Design 2: combined icons would show up like normal icons in the stylesheet
Drawbacks Design 2: need for hard coded combined icons

Activity

  1. changed the title [-]Support Multi-icon symbols or Multi-sprite icons[/-] [+]Support multi-icon symbols or multi-sprite icons[/+] on Mar 3, 2017
  2. added
    cross-platform 📺
    on Mar 16, 2017
  3. 1ec5 commented on Mar 26, 2017

    @1ec5
    Contributor

    /cc @mapbox/gl

  4. changed the title [-]Support multi-icon symbols or multi-sprite icons[/-] [+]Support multi-icon/multi-text symbols[/+] on Nov 22, 2017
  5. jfirebaugh commented on Nov 22, 2017

    @jfirebaugh
    Contributor

    Combining this with the very similar #4436. Note the nice example there:

    2017-03-16 8 03 25

  6. ak0lmak0v commented on May 2, 2018

    @ak0lmak0v

    is it even possible to realize?
    and how many changes need to be done in the render methods?

  7. anandthakker commented on Jun 27, 2018

    @anandthakker
    Contributor

    Expressions open up the door for a different design alternative: some kind of symbol-layout expression that's used to compose icons and runs of text into a single 'rich symbol' that's then treated as a single unit for placement/collision/z-ordering purposes.

    Something like:

      // new "symbol-content" layer property, incompatible with the "text-field", "icon-image", and "*-{offset,ignore-placement,allow-overlap}" properties
      "symbol-content": [ "symbol-layout",
        ["text", ["get", "name"], { size: 13, offset: ..., color: ...}],
        ["text", ["get", "population_density"], { size: 11, offset: ..., color: ...}],
        ["text", "ppl / km^2", { size: 11, offset: ..., color: ...}],
        ["icon", "dot.sdf", { size: ..., offset: ..., color: ... }],
        ...
      ]
  8. ChrisLoer commented on Jul 24, 2018

    @ChrisLoer
    Contributor

    We're making progress on this in #7015, which adds support for multiple fonts/sizes within a single text label. Controlling paint properties (e.g. color) and adding multiple icons will go in later PRs.

  9. 1ec5 commented on Aug 18, 2018

    @1ec5
    Contributor

    The current road name label in the navigation SDK could take advantage of this option to display a route shield alongside a road name in a single point-placed symbol. The iOS implementation uses a native view (mapbox/mapbox-navigation-ios#1576), but runtime styling would be desirable for the Android implementation (mapbox/mapbox-navigation-android#1222) for various reasons, so this feature would allow us to achieve the same effect on both platforms.

    shield-280-junipero-serra-fwy

  10. changed the title [-]Support multi-icon/multi-text symbols[/-] [+]Support multi-icon symbols[/+] on Oct 15, 2018
  11. ChrisLoer commented on Oct 15, 2018

    @ChrisLoer
    Contributor

    Renaming this to "Support multi-icon symbols" as multi-text has landed on GL JS as #6994 and on GL Native as mapbox/mapbox-gl-native#12624.

    Example here: https://www.mapbox.com/mapbox-gl-js/example/display-and-style-rich-text-labels/

  12. removed their assignment
    on Oct 15, 2018
  13. Tomcatus commented on May 18, 2020

    @Tomcatus

    Hi guys, I was wondering if there was any update on this feature or any similar one that would enable putting two images over each other in one Symbol layer?

  14. shayanaijaz commented on Mar 5, 2021

    @shayanaijaz

    I am also looking for an update on this issue and wondering if this is something that is still being worked on.

  15. asheemmamoowala commented on Mar 6, 2021

    @asheemmamoowala
    Contributor

    @shayanaijaz This is not on our roadmap at this time, but we did introduce formatted text with inline image support in v1.6. See this blog post for more details.

  16. jasongoodwin commented on Jan 4, 2022

    @jasongoodwin

    This is 100% possible with the expression syntax.

                    {
                    'type': 'Feature',
                    'geometry': {
                        'type': 'Point',
                        'coordinates': [this.long, this.lat]
                    },
                    'properties': {
                        'icon': 'bus-generic'
                    }}
    
    

    If you have a property, you can query it and use it in the layer definition to display different icons:

    
       map.addLayer({
           'id': 'bus-layer',
           'type': 'symbol',
           'source': 'bus-source', // reference the data source
           'layout': {
               'icon-image': ['get', 'icon'], // reference the icon in properties
               'icon-size': 0.2,
           }
       });
       ```
    
    See this example over here!
    https://docs.mapbox.com/mapbox-gl-js/example/add-image-missing-generated/
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cross-platform 📺feature 🍏

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions