pub struct Document {
pub name: String,
pub version: String,
pub tile_size: u32,
pub pad: u32,
pub params: IndexMap<String, ParamDecl>,
pub attribution: Option<String>,
pub functions: IndexMap<String, FuncDecl>,
pub legend: Option<LegendDecl>,
pub sources: IndexMap<String, SourceDecl>,
pub nodes: IndexMap<String, NodeSpec>,
pub output: NodeRef,
}Expand description
A parsed style document. Order of nodes is preserved (for
deterministic error messages) but does not imply evaluation order —
that is derived by topological sort of the DAG.
Fields§
§name: String§version: String§tile_size: u32Rendered tile edge in pixels. Every *-px field in the document
is measured against this, so it decides what a pixel is worth in
ground units: the same width-px covers twice the ground at 256
as it does at 512. Defaults to 512, MapLibre’s vector-tile
convention, so px numbers carry across from a MapLibre style
unchanged.
pad: u32§params: IndexMap<String, ParamDecl>§attribution: Option<String>Attribution for the style itself (HTML allowed, like MapLibre).
Per-source attributions live on the sources entries; hosts
merge both with upstream metadata (TileJSON / PMTiles) — see
Document::attributions.
functions: IndexMap<String, FuncDecl>User-defined functions: reusable node subgraphs called with
{ "op": "func", "fn": "<name>", ...args }. Expanded inline at
graph-build time — see expand_functions.
legend: Option<LegendDecl>What the map’s symbols mean. Never rendered into a tile — hosts
read it to draw a legend beside the map. See LegendDecl.
sources: IndexMap<String, SourceDecl>External data the host provides. Mixes document-scoped resources
(brush, image, sprite, font) — resolved once per style —
and tile-scoped
pyramids (mvt, pmtiles, dem) — fetched per tile. The
type discriminator selects the variant.
Per-tile variants bind their payload under tile.<source-name>
for source nodes to consume. Document-scoped variants are
referenced by @source-name in node fields (the legacy
assets block from 0.2 is gone — its entries move here).
nodes: IndexMap<String, NodeSpec>§output: NodeRefNode id (with or without @ prefix) that produces the final raster.
Implementations§
Source§impl Document
impl Document
Sourcepub fn from_json(s: &str) -> Result<Self, StyleError>
pub fn from_json(s: &str) -> Result<Self, StyleError>
Parse a style document. // line and /* … */ block comments are
allowed anywhere JSON allows whitespace; they are blanked in place
before parsing, so an error’s line and column still point into the
text as written.
Sourcepub fn attributions(&self) -> Vec<&str>
pub fn attributions(&self) -> Vec<&str>
Every attribution string declared in the document: the style’s
own attribution plus each source’s, in declaration order,
deduplicated. Upstream metadata (TileJSON attribution,
PMTiles metadata) is a host concern — hosts merge it with this
list after opening their sources.
Sourcepub fn subgraph(&self, target: &str) -> Option<Document>
pub fn subgraph(&self, target: &str) -> Option<Document>
A document that produces just target: that node, everything it
transitively references, and nothing else. None when target
is not a node in this document.
Rendering one node of a style — a legend swatch is the reason to want that — needs no special support from the evaluator if the document handed to it says that node is the output. Nodes the target does not depend on are left out rather than evaluated and discarded, which also keeps a swatch from failing on a DEM or raster source that belongs to some other layer.
params, functions and sources come along whole — they are
declarations, and an unused one costs nothing. The legend does
not: its entries point at nodes that are probably no longer here.
Sourcepub fn params_schema(&self) -> Value
pub fn params_schema(&self) -> Value
JSON Schema describing the parameter values object a caller
may pass when rendering this style (CLI --param, server query
string, library ParamValues). Derived from the document’s
params declarations: numbers carry minimum / maximum,
colors a hex-string pattern, and every entry its declared
default / description. Editor UIs can drive sliders and
color pickers straight off this.