Skip to main content

Crate drawland_graph

Crate drawland_graph 

Source
Expand description

§drawland-graph

The draw.land library, in Rust: every function a map style calls (features.tiles, areas.union, fills.fill, modules.roads, compose.mask…), its checks, defaults and error messages, building the graph of operations draw.land’s engine draws as a layered pen-plotter SVG.

City Grain

It is the one implementation behind every face of draw.land: JavaScript and TypeScript profiles (drawland-script), import drawland in Python, require('drawland') in Node, and this crate’s typed API for Rust. The same calls give the same graph in each.

use drawland_graph::{obj, Graph};

let mut g = Graph::new(None);
g.output(obj! { "lat" => 37.802, "lng" => -122.263, "width" => "6in", "height" => "4in", "scale" => "1:8000" })?;
let b = g.features().tiles(&["buildings"])?;
let buildings = g.areas().polygons(&b)?;
let roofs = g.fills().fill(obj! { "in" => &buildings, "pattern" => "lines", "angle" => 45, "spacing" => "0.6mm" })?;
g.draw(obj! { "id" => "roofs", "from" => &roofs })?;
let rings = g.lines().rings(&buildings, obj! {})?;
g.draw(obj! { "id" => "buildings", "from" => &rings })?;
let graph = g.finish()?; // what drawland-core draws
  • Handles are typed: Features, Area, Lines; options are objects (obj!) with the keys of the reference at draw.land/docs.
  • g.view(spec, |g| …) draws another place into a rectangle of the page; g.output_remap(spec, &mut [&mut f]) takes a projection of your own as a Rust function of page points.
  • g.page() and g.world() answer about the frame while you build: world().to_page(lat, lng), page().to_world([x, y]), world().zoom().
  • Ranges by zoom or scale, as a Mapbox style writes them: world().at(json!(["step", ["zoom"], 1, 15, 3])), or the same array in a call’s options, is worked out for the map’s zoom.
  • Graph::call(name, args) is the library by name, as the other languages call it.

To draw the graph with the downloads included, use the drawland crate: Drawer::draw(&Profile::graph(graph), …).

Source and docs: github.com/piLeoni/drawland. MIT.

Re-exports§

pub use api::Area;
pub use api::Features;
pub use api::Lines;

Modules§

api
The library for Rust: the same functions a JavaScript or Python profile calls, as methods. Handles are typed (Features, Area, Lines); options are objects (crate::obj!), with the keys the library documents (drawland.d.ts, the reference at draw.land/docs).

Macros§

obj
An object written in Rust: obj! { "pattern" => "dots", "spacing" => "0.45mm", "in" => &parks }.

Structs§

At
Where a script wrote something: line and column, from 1. Written as line 12 column 5, the form the web editor’s markers read.
Error
What went wrong, and where in the script when the caller said (Graph::at).
Grammar
Graph
A draw.land graph, built a call at a time.
Obj
An object: keys in the order they were written.

Enums§

Arg
A value passed to or returned by the library.
Lazy
Which part of a module a Lazy is, and what it was made from.

Constants§

FUNCTIONS
Every function of the library, as a script names it: what drawland.d.ts declares and the Python package exposes.
PROPERTIES
The values a script reads rather than calls: page.width, world.center…
VIEW_DEPTH
How deep views may nest (a view drawing a style that has views of its own).

Functions§

describe
How an error names what it got: an area, the string "x", nothing.
find_at
The first line N column M in a message.
is_remap
A warp that is a remap, still holding its function.
number
A number as JSON: a whole number as an integer, as a script writes it.
show_number
A number as JavaScript prints it: 3, 0.5, -2.25.

Type Aliases§

Result