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

case expression returns null instead of fallback

Open korywka opened this issue 1 year ago • 2 comments

mapbox-gl-js version: 2.9.0

Question

case fallback value works well for == condition, but not >= if property is not set:

https://observablehq.com/@mourner/mapbox-gl-expression-playground

null instead of #fallback:

image

but it works for ==:

image

Can't find where this behaviour is documented: https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/

Am I missing something?

korywka avatar Aug 07 '22 21:08 korywka

I believe I have the same issue.

This expression renders correctly, ie. the fallback is used for shapes whose INTFLD is not 1 or 3, including nulls.

  "fill-color": 
      ["case",
          ["==", ["get", "INTFLD"], 1],
          ["rgba", 255, 0, 0, 1],
          ["==", ["get", "INTFLD"], 3],
          ["rgba", 0, 255, 0, 1],
          ["rgba", 255, 255, 0, 0.5]            
      ]

Whereas with this:

  "fill-color": 
      ["case", 
        ["all", 
          [">=", ["get", "INTFLD"], 0],
          ["<", ["get", "INTFLD"], 2]
        ],
        ["rgba", 255, 0, 0, 1],
        ["all",
          [">=", ["get", "INTFLD"], 2],
          ["<", ["get", "INTFLD"], 3]
        ],
        ["rgba", 0, 255, 0, 1],
        ["rgba", 255, 255, 0, 0.5]
      ]

the fallback is used, but NOT where INTFLD is null. Shapes with null values render black.

stevespralja avatar Aug 29 '22 04:08 stevespralja

yes, looks like the same bug.

korywka avatar Aug 29 '22 13:08 korywka