mapbox-gl-js
mapbox-gl-js copied to clipboard
Issue with expression?
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", []].
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]