0

I try to style my Mapbox layer using a case expression. My expression is quite simple and should for different integer ranges set different colors. Although doing the same as provided in examples, it must contain an error, and all lines are only visualized in black (although this is not the default color I set). After searching for hours, I still cannot find out why it won't work.

"line-color": [
      "case",
      [">=", ["to-number", ["get", "temperature"]],  30],
      "green",
      [">=", ["to-number", ["get", "temperature"]],  50],
      "red",
      "blue"
   

I included a default value, I tried it with and without the to-number operation (although it is a number value), I tried to put the values 30 and 50 into quotes or brackets.

I also tried setting it as interpolation expression.

"line-color": [
  "interpolate",
  ["linear"],
  ["to-number", ["get", "temperature"]],
  10, "green",
  50, "red",
  150, "blue"
]

Any ideas what I am doing wrong?

Edit: I try to visualize the results in QGIS, if that matters.

UPDATE: I found the Mapbox GL Style Validator and with this I do not get any errors. Unfortunately, the case still does not work, but I can do it with filters by splitting up my temperature layer and setting a filter for each range. Of course this is not a good solution as it enlarges my styling code significantly.

Robbert
  • 109
  • 5
  • do you see anything in console log? if there's an issue with the expression itself the console log should throw an error. What is the input? It would be better to see more code – Peter Feb 14 '23 at 08:56
  • Where in QGIS can I see that? In the developer tools there isn't shown any error. I only apply this style.json file to a created vector tile service, so I do not have any frontend code available. – Robbert Feb 14 '23 at 09:58

1 Answers1

0

Hard to tell with the information provided, but this result would be consistent with data that contains values that can't be converted to numbers.

You can try this:

"line-color": [
      "case",
      [">=", ["to-number", ["get", "temperature"], 0],  30],
      "green",
      [">=", ["to-number", ["get", "temperature"], 0],  50],
      "red",
      "blue"
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
  • Unfortunately it doesn't work. I am sorry for not being able providing more information, but I just do not know how I could. I basically have some .mvt files and the .json style. I found a workaround using filters and splitting my temperature layers up, but this is not really a nice way and it would be exactly the sense of the case function or interpolate to only have one layer. – Robbert Feb 15 '23 at 04:47