mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Issue with expression?

Open ramusbucket opened this issue 1 year ago • 1 comments

mapbox-gl npm package: 2.10.0

Question

let visited = [1,2,3];

map.addLayer({
  id: layer_name,
  type: "symbol",
  source: source_name,
  layout: {
    "icon-image": [
      "case",
      [">", ["index-of", ["get", "id"], visited], -1],
      "visited-icon",
      "normal-icon",
    ],
    "icon-size": 0.25,        
    "icon-allow-overlap": true,
  },
});

I get following error for that icon-image expression

layers.marker_layer.layout.icon-image[1][1][2]: Expected an array with at least one element. 
If you wanted a literal array, use ["literal", []].

ramusbucket avatar Sep 21 '22 18:09 ramusbucket

As the error message says, you need the "literal" expression to use an array in expressions, like so:

">", ["index-of", ["get", "id"], ["literal", visited]], -1]

SnailBones avatar Sep 21 '22 21:09 SnailBones