Skip to content

GridSourceSchema

const GridSourceSchema: ZodObject<{ attribution: ZodOptional<ZodString>; bands: ZodOptional<ZodArray<ZodNumber, "many">>; bounds: ZodOptional<ZodTuple<[ZodNumber, ZodNumber, ZodNumber, ZodNumber], null>>; cache: ZodOptional<ZodObject<{ enabled: ZodDefault<ZodBoolean>; ttl: ZodOptional<ZodNumber>; }, "strip", ZodTypeAny, { enabled: boolean; ttl?: number; }, { enabled?: boolean; ttl?: number; }>>; encoding: ZodEnum<["rg-uv", "scalar-r", "nullschool-json", "geotiff"]>; grid: ZodOptional<ZodObject<{ dx: ZodNumber; dy: ZodNumber; la1: ZodNumber; lo1: ZodNumber; nx: ZodNumber; ny: ZodNumber; }, "strip", ZodTypeAny, { dx: number; dy: number; la1: number; lo1: number; nx: number; ny: number; }, { dx: number; dy: number; la1: number; lo1: number; nx: number; ny: number; }>>; loading: ZodOptional<ZodObject<{ enabled: ZodDefault<ZodBoolean>; message: ZodOptional<ZodString>; showErrorOverlay: ZodDefault<ZodBoolean>; }, "strip", ZodTypeAny, { enabled: boolean; message?: string; showErrorOverlay: boolean; }, { enabled?: boolean; message?: string; showErrorOverlay?: boolean; }>>; nodata: ZodOptional<ZodUnion<[ZodNumber, ZodObject<{ above: ZodOptional<ZodNumber>; below: ZodOptional<ZodNumber>; channel: ZodEnum<["r", "g", "b", "a"]>; equals: ZodOptional<ZodNumber>; }, "strip", ZodTypeAny, { above?: number; below?: number; channel: "a" | "b" | "r" | "g"; equals?: number; }, { above?: number; below?: number; channel: "a" | "b" | "r" | "g"; equals?: number; }>]>>; range: ZodOptional<ZodTuple<[ZodNumber, ZodNumber], null>>; type: ZodLiteral<"grid">; units: ZodOptional<ZodString>; url: ZodString; }, "strip", ZodTypeAny, { attribution?: string; bands?: number[]; bounds?: [number, number, number, number]; cache?: { enabled: boolean; ttl?: number; }; encoding: "geotiff" | "rg-uv" | "scalar-r" | "nullschool-json"; grid?: { dx: number; dy: number; la1: number; lo1: number; nx: number; ny: number; }; loading?: { enabled: boolean; message?: string; showErrorOverlay: boolean; }; nodata?: number | { above?: number; below?: number; channel: "a" | "b" | "r" | "g"; equals?: number; }; range?: [number, number]; type: "grid"; units?: string; url: string; }, { attribution?: string; bands?: number[]; bounds?: [number, number, number, number]; cache?: { enabled?: boolean; ttl?: number; }; encoding: "geotiff" | "rg-uv" | "scalar-r" | "nullschool-json"; grid?: { dx: number; dy: number; la1: number; lo1: number; nx: number; ny: number; }; loading?: { enabled?: boolean; message?: string; showErrorOverlay?: boolean; }; nodata?: number | { above?: number; below?: number; channel: "a" | "b" | "r" | "g"; equals?: number; }; range?: [number, number]; type: "grid"; units?: string; url: string; }>

Defined in: packages/core/src/schemas/sources/grid.ts:69

A grid source: a regular raster field on a latitude/longitude grid that page code samples by position, read by maplibre-yaml rather than drawn by MapLibre (no layer type draws one yet).

Closed on purpose: MapLibre never reads this object, so there is no reason to pass unknown keys through, and a misspelt key gets a did-you-mean instead of silence. Zod’s default strip object (not .strict(), not marked open): the unknown-key walker only descends into a union member whose parse succeeds, so a strict object would report a typo as a wrong type rather than suggest the key.

Cross-field rules (bounds: or grid: per encoding, range: per encoding, nodata: shape, bands: only with geotiff, bounds order and extent) live in parser/grid-checks.ts: the source union is at the TypeScript instantiation-depth limit and cannot take another refinement.

Geometry comes in two forms, never both: bounds are the cell edges, in MapLibre’s [west, south, east, north] order; grid names the nodes (lo1/la1 is the centre of node (0, 0), dx east and dy south, both positive). nullschool-json and geotiff files carry their own geometry.

sources:
temperature:
type: grid
url: data/temperature.png
encoding: scalar-r
bounds: [-180, -90, 180, 90]
range: [193, 328]
units: K
current:
type: grid
url: data/current-uv.png
encoding: rg-uv
grid: { nx: 360, ny: 181, lo1: -180, la1: 90, dx: 1, dy: 1 }
range: [-5, 5]
units: m/s
nodata: { channel: a, equals: 0 }
elevation:
type: grid
url: data/elevation.tif
encoding: geotiff
bands: [0]
nodata: -9999