Description
I'd like to have config
properties that are expressions. I'd also like those expressions to be able to use feature properties, like so:
{
"schema": {
"room-color": {
"type": "color",
"default": ["case", ["==", ["get", "room-type"], "administrative"], "red", "blue"]
}
},
"layers": [
"id": "rooms-fill",
"type": "fill",
"paint": {
"fill-color": ["config", "room-color"]
}
]
}
This is only partly supported ATM, because of (at least) two issues I bumped into while stepping through the evaluation code path in one of the workers:
-
The expression assigned to
fill-color
above is considered feature constant, and so feature data is not loaded during evaluation. This can be hacked around by wrapping the whole thing into e.g. alet
with aget
– but this is suboptimal (think["let", "_" ["get", "room-type"], ["config", "room-color"]]
). -
Evaluating a
match
expression in the worker fails and defaults to the "otherwise" branch, if the expression being evaluated is a config expression. This happens here as thetypeOf(input) === this.inputType
check returnsfalse
, probably because the type constants in the worker are not referentially the same as the{kind: ...}
value from the unserialized version of the config expression from the main thread(?).
mapbox-gl-js version: 3.11.0
browser: Arc
Link to Demonstration
https://codesandbox.io/p/sandbox/lxfnlg?file=%2Findex.html%3A39%2C20
(If both of these issues are fixed, one of the squares should be red.)