Skip to content

Multiple issues wrt. feature-dependent config expressions #13452

Open
@brncsk

Description

@brncsk

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:

  1. 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. a let with a get – but this is suboptimal (think ["let", "_" ["get", "room-type"], ["config", "room-color"]]).

  2. 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 the typeOf(input) === this.inputType check returns false, 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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions