Atlaslog / Field Notes / Styling & rendering
Field note · Styling & rendering
A style expression of the wrong type hides the entire layer
Quick answer
The layer and its legend are present but no feature is drawn, and the console shows a single warning. A property name was written as a bare string instead of `["get", ...]`, or `fill-opacity` received a string, so type validation rejects the paint and the layer draws nothing.
Symptom
- `Error: layers.districts.paint.fill-color: Expected number but found string in expression: ["get", "level"]`
- `Error: layers.districts.paint.fill-opacity: "level" is not a valid expression`
- `map.queryRenderedFeatures({ layers: ['districts'] })` returns an empty array while `map.getStyle().layers` contains the layer
Checklist
- List layer ids from `map.getStyle().layers` and confirm `map.getLayer('districts')` is not undefined
- Replace the paint expression with a constant color and see whether features appear
- Check whether a property name was written as a bare string instead of `["get", ...]`
- Wrap the value in `["to-number", ["get", ...]]` and retest
- Confirm the property exists and inspect its type in the source data
Fix
Use array expressions with explicit conversion: `'fill-color': ['interpolate', ['linear'], ['to-number', ['get', 'pop_density']], 0, '#e8f4ff', 5000, '#8ec4ff', 20000, '#1a6fd4']` and `'fill-opacity': ['case', ['==', ['get', 'level'], 'city'], 0.75, 0.45]`.
Code
Error: layers.districts.paint.fill-color: Expected number but found string
in expression: ["get", "level"]Error: layers.districts.paint.fill-opacity: "level" is not a valid expression
Watch out
- Writing `"level"` as a literal string in expression context and expecting it to be read as a property name
- Feeding a string property to `fill-opacity`, which drops the whole layer instead of only the offending features
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Atlaslog (2026). A style expression of the wrong type hides the entire layer. https://www.jingweizhi.com/en/cookbook/style-expression-missing-property.html (accessed 2026-11-03).