Skip to main content

Document

Struct Document 

Source
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: u32

Rendered 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: NodeRef

Node id (with or without @ prefix) that produces the final raster.

Implementations§

Source§

impl Document

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Document

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.