I would like to set an icon-image based on a data value (https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions).
Also see https://github.com/mapbox/mapbox-gl-js/issues/6935 which has a few examples for how to do this.
I've tried a few things ...
Using match
'icon-image': [
'match',
['get', 'tap_ports'],
2,
'{tubes}-circle-15',
4,
'{tubes}-square-15',
8,
'{tubes}-octagon-15',
'{tubes}-circle-15' // default
]
Using case
'icon-image': [
'case',
['==', ['get', 'tap_ports'], 2],
'{tubes}-circle-15',
['==', ['get', 'tap_ports'], 4],
'{tubes}-square-15',
['==', ['get', 'tap_ports'], 4],
'{tubes}-octagon-15',
'{tubes}-circle-15' // default
]
Using property and stops
'icon-image': {
property: 'tap_ports',
type: 'categorical',
stops: [
[2, '{tubes}-circle-15'],
[4, '{tubes}-square-15'],
[8, '{tubes}-octagon-15']
]
}
All of those don't produce any icons.
Also, if I try to log the rendered features from that layer using queryRenderedFeatures I see only empty arrays, so the features aren't rendering due to my attempts.
If I simply set
'icon-image': '{tubes}-circle-15'
everything renders fine, but only as circles of course.