mapbox-gl-js version: v0.44.0
It would be great if I could use expressions in each element of an array value for properties like text-font and *-translate.
Lets take text-offset for example. The output value is a 2-element array. As a literal, can be written like this:
Lets imagine a hypothetical situation where I wanted to offset along the y axis based on the existence of a property in my data. This would be a useful feature if I had icons for some labels but not for others. I can write this expression like so, and it's valid:
[
"case",
["has", "icon"],
["literal", [0, -10]],
["literal", [0, 0]]
]
If I have more than one case where I want to adjust my y axis value (say, to check for the existence of 'big-icon' and 'small-icon'), the syntax gets even more unwieldy:
[
"case",
["has", "icon-small"],
["literal", [0, -10]],
["has", "icon-large"],
["literal", [0, -20]],
["literal", [0, 0]]
]
It would be amazing if the following was valid:
[
0,
[ "case",
["has", "icon-small"],
-10
["has", "icon-large"],
-20,
0
]
]
Now, that probably won't work because of the way the expression syntax is designed. Could a to-array expression get me what I want?
[
"to-array",
0,
[ "case", ["has", "icon"], -10, 0]
]
This would be a really valuable feature for many properties, and particularly text-font, where usually users will have a universal fallback font, but would want to use an expression to dictate what the primary font is. It would also lead to a more user-friendly experience in Studio!
mapbox-gl-js version: v0.44.0
It would be great if I could use expressions in each element of an array value for properties like
text-fontand*-translate.Lets take
text-offsetfor example. The output value is a 2-element array. As a literal, can be written like this:Lets imagine a hypothetical situation where I wanted to offset along the y axis based on the existence of a property in my data. This would be a useful feature if I had icons for some labels but not for others. I can write this expression like so, and it's valid:
If I have more than one case where I want to adjust my y axis value (say, to check for the existence of 'big-icon' and 'small-icon'), the syntax gets even more unwieldy:
It would be amazing if the following was valid:
Now, that probably won't work because of the way the expression syntax is designed. Could a
to-arrayexpression get me what I want?This would be a really valuable feature for many properties, and particularly text-font, where usually users will have a universal fallback font, but would want to use an expression to dictate what the primary font is. It would also lead to a more user-friendly experience in Studio!