1
votes

I have an expression that I am using in a mapbox map to decide which icon I want to show. It looks like this:

"icon-image": [
  "case",
  ["==", ["get", "matched"], "True"],
  "greenmarkertick",
  "redmarkercross",
]

I need to add another condition to this expression, as when matched is True but something else doesn't match, in this case:

["!=", ["get", "vehicle"], ["get", "standstill_vehicle"]]

I have tried adding this directly to my case expression, like so:

"icon-image": [
  "case",
  ["==", ["get", "matched"], "True"],
  "greenmarker",
  ["!=", ["get", "vehicle"], ["get", "standstill_vehicle"]],
  "orangemarker",
  "redmarker",
]

but this didn't work.

Basically what I need is an expression that checks if the the matched property is true and then checks to see if the vehicle properties match.

If they do display a green marker, if they don't display an orange marker. If matched is false then a red marker should be displayed.

Any help with this would be much appreciated.

1

1 Answers

2
votes

I realised that the positioning of the expressions in the case expression does matter. So , I solved my problem with the following expression:

"icon-image": [
  "case",
  ["all", ["==", ["get", "matched"], "True"], ["!=", ["get", "vehicle"], ["get", "standstill_vehicle"]]],
  "orangemarker",
  ["==", ["get", "matched"], "True"],
  "greenmarker",
  "redmarker",
]