Struct StaticMapBuilder

Source
pub struct StaticMapBuilder { /* private fields */ }
Expand description

Builder for StaticMap.

Implementations§

Source§

impl StaticMapBuilder

Source

pub fn new() -> Self

Create a new builder with defaults.

Examples found in repository?
examples/empty_map.rs (line 4)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(300)
6        .height(300)
7        .zoom(4)
8        .lon_center(4.)
9        .lat_center(54.)
10        .build()?;
11
12    map.save_png("empty_map.png")?;
13
14    Ok(())
15}
More examples
Hide additional examples
examples/circle.rs (line 7)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(200)
9        .height(200)
10        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
11        .zoom(5)
12        .build()?;
13
14    let circle_outline = CircleBuilder::new()
15        .lon_coordinate(10.)
16        .lat_coordinate(47.)
17        .color(Color::new(true, 255, 255, 255, 255))
18        .radius(9.)
19        .build()?;
20
21    let circle = CircleBuilder::new()
22        .lon_coordinate(10.)
23        .lat_coordinate(47.)
24        .color(Color::new(true, 0, 0, 255, 255))
25        .radius(6.)
26        .build()?;
27
28    map.add_tool(circle_outline);
29    map.add_tool(circle);
30
31    map.save_png("circle.png")?;
32
33    Ok(())
34}
examples/icon.rs (line 4)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(200)
6        .height(200)
7        .padding((80, 0))
8        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
9        .zoom(12)
10        .build()?;
11
12    let icon_flag = IconBuilder::new()
13        .lon_coordinate(6.63204)
14        .lat_coordinate(45.85378)
15        .x_offset(12.)
16        .y_offset(32.)
17        .path("examples/icons/icon-flag.png")?
18        .build()?;
19
20    let icon_factory = IconBuilder::new()
21        .lon_coordinate(6.6015)
22        .lat_coordinate(45.8485)
23        .x_offset(18.)
24        .y_offset(18.)
25        .path("examples/icons/icon-factory.png")?
26        .build()?;
27
28    map.add_tool(icon_flag);
29    map.add_tool(icon_factory);
30
31    map.save_png("icon.png")?;
32
33    Ok(())
34}
examples/line.rs (line 7)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(300)
9        .height(400)
10        .padding((10, 0))
11        .build()
12        .unwrap();
13
14    let lat: &[f64] = &[52.5, 48.9];
15    let lon: Vec<f64> = vec![13.4, 2.3];
16
17    let red = Color::new(true, 255, 0, 0, 255);
18    let white = Color::new(true, 255, 255, 255, 255);
19
20    let line = LineBuilder::new()
21        .lat_coordinates(lat.into_iter().copied())
22        .lon_coordinates(lon.clone())
23        .width(3.)
24        .simplify(true)
25        .color(red)
26        .build()?;
27
28    let underline = LineBuilder::new()
29        .lat_coordinates(lat.into_iter().copied())
30        .lon_coordinates(lon)
31        .width(5.)
32        .simplify(true)
33        .color(white)
34        .build()?;
35
36    map.add_tool(underline);
37    map.add_tool(line);
38
39    map.save_png("line.png")?;
40
41    Ok(())
42}
Source

pub fn width(self, width: u32) -> Self

Image width, in pixels. Default is 300.

Examples found in repository?
examples/empty_map.rs (line 5)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(300)
6        .height(300)
7        .zoom(4)
8        .lon_center(4.)
9        .lat_center(54.)
10        .build()?;
11
12    map.save_png("empty_map.png")?;
13
14    Ok(())
15}
More examples
Hide additional examples
examples/circle.rs (line 8)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(200)
9        .height(200)
10        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
11        .zoom(5)
12        .build()?;
13
14    let circle_outline = CircleBuilder::new()
15        .lon_coordinate(10.)
16        .lat_coordinate(47.)
17        .color(Color::new(true, 255, 255, 255, 255))
18        .radius(9.)
19        .build()?;
20
21    let circle = CircleBuilder::new()
22        .lon_coordinate(10.)
23        .lat_coordinate(47.)
24        .color(Color::new(true, 0, 0, 255, 255))
25        .radius(6.)
26        .build()?;
27
28    map.add_tool(circle_outline);
29    map.add_tool(circle);
30
31    map.save_png("circle.png")?;
32
33    Ok(())
34}
examples/icon.rs (line 5)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(200)
6        .height(200)
7        .padding((80, 0))
8        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
9        .zoom(12)
10        .build()?;
11
12    let icon_flag = IconBuilder::new()
13        .lon_coordinate(6.63204)
14        .lat_coordinate(45.85378)
15        .x_offset(12.)
16        .y_offset(32.)
17        .path("examples/icons/icon-flag.png")?
18        .build()?;
19
20    let icon_factory = IconBuilder::new()
21        .lon_coordinate(6.6015)
22        .lat_coordinate(45.8485)
23        .x_offset(18.)
24        .y_offset(18.)
25        .path("examples/icons/icon-factory.png")?
26        .build()?;
27
28    map.add_tool(icon_flag);
29    map.add_tool(icon_factory);
30
31    map.save_png("icon.png")?;
32
33    Ok(())
34}
examples/line.rs (line 8)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(300)
9        .height(400)
10        .padding((10, 0))
11        .build()
12        .unwrap();
13
14    let lat: &[f64] = &[52.5, 48.9];
15    let lon: Vec<f64> = vec![13.4, 2.3];
16
17    let red = Color::new(true, 255, 0, 0, 255);
18    let white = Color::new(true, 255, 255, 255, 255);
19
20    let line = LineBuilder::new()
21        .lat_coordinates(lat.into_iter().copied())
22        .lon_coordinates(lon.clone())
23        .width(3.)
24        .simplify(true)
25        .color(red)
26        .build()?;
27
28    let underline = LineBuilder::new()
29        .lat_coordinates(lat.into_iter().copied())
30        .lon_coordinates(lon)
31        .width(5.)
32        .simplify(true)
33        .color(white)
34        .build()?;
35
36    map.add_tool(underline);
37    map.add_tool(line);
38
39    map.save_png("line.png")?;
40
41    Ok(())
42}
Source

pub fn height(self, height: u32) -> Self

Image height, in pixels. Default is 300.

Examples found in repository?
examples/empty_map.rs (line 6)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(300)
6        .height(300)
7        .zoom(4)
8        .lon_center(4.)
9        .lat_center(54.)
10        .build()?;
11
12    map.save_png("empty_map.png")?;
13
14    Ok(())
15}
More examples
Hide additional examples
examples/circle.rs (line 9)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(200)
9        .height(200)
10        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
11        .zoom(5)
12        .build()?;
13
14    let circle_outline = CircleBuilder::new()
15        .lon_coordinate(10.)
16        .lat_coordinate(47.)
17        .color(Color::new(true, 255, 255, 255, 255))
18        .radius(9.)
19        .build()?;
20
21    let circle = CircleBuilder::new()
22        .lon_coordinate(10.)
23        .lat_coordinate(47.)
24        .color(Color::new(true, 0, 0, 255, 255))
25        .radius(6.)
26        .build()?;
27
28    map.add_tool(circle_outline);
29    map.add_tool(circle);
30
31    map.save_png("circle.png")?;
32
33    Ok(())
34}
examples/icon.rs (line 6)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(200)
6        .height(200)
7        .padding((80, 0))
8        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
9        .zoom(12)
10        .build()?;
11
12    let icon_flag = IconBuilder::new()
13        .lon_coordinate(6.63204)
14        .lat_coordinate(45.85378)
15        .x_offset(12.)
16        .y_offset(32.)
17        .path("examples/icons/icon-flag.png")?
18        .build()?;
19
20    let icon_factory = IconBuilder::new()
21        .lon_coordinate(6.6015)
22        .lat_coordinate(45.8485)
23        .x_offset(18.)
24        .y_offset(18.)
25        .path("examples/icons/icon-factory.png")?
26        .build()?;
27
28    map.add_tool(icon_flag);
29    map.add_tool(icon_factory);
30
31    map.save_png("icon.png")?;
32
33    Ok(())
34}
examples/line.rs (line 9)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(300)
9        .height(400)
10        .padding((10, 0))
11        .build()
12        .unwrap();
13
14    let lat: &[f64] = &[52.5, 48.9];
15    let lon: Vec<f64> = vec![13.4, 2.3];
16
17    let red = Color::new(true, 255, 0, 0, 255);
18    let white = Color::new(true, 255, 255, 255, 255);
19
20    let line = LineBuilder::new()
21        .lat_coordinates(lat.into_iter().copied())
22        .lon_coordinates(lon.clone())
23        .width(3.)
24        .simplify(true)
25        .color(red)
26        .build()?;
27
28    let underline = LineBuilder::new()
29        .lat_coordinates(lat.into_iter().copied())
30        .lon_coordinates(lon)
31        .width(5.)
32        .simplify(true)
33        .color(white)
34        .build()?;
35
36    map.add_tool(underline);
37    map.add_tool(line);
38
39    map.save_png("line.png")?;
40
41    Ok(())
42}
Source

pub fn padding(self, padding: (u32, u32)) -> Self

Padding between map features and edge of map in x and y direction. Default is (0, 0).

Examples found in repository?
examples/icon.rs (line 7)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(200)
6        .height(200)
7        .padding((80, 0))
8        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
9        .zoom(12)
10        .build()?;
11
12    let icon_flag = IconBuilder::new()
13        .lon_coordinate(6.63204)
14        .lat_coordinate(45.85378)
15        .x_offset(12.)
16        .y_offset(32.)
17        .path("examples/icons/icon-flag.png")?
18        .build()?;
19
20    let icon_factory = IconBuilder::new()
21        .lon_coordinate(6.6015)
22        .lat_coordinate(45.8485)
23        .x_offset(18.)
24        .y_offset(18.)
25        .path("examples/icons/icon-factory.png")?
26        .build()?;
27
28    map.add_tool(icon_flag);
29    map.add_tool(icon_factory);
30
31    map.save_png("icon.png")?;
32
33    Ok(())
34}
More examples
Hide additional examples
examples/line.rs (line 10)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(300)
9        .height(400)
10        .padding((10, 0))
11        .build()
12        .unwrap();
13
14    let lat: &[f64] = &[52.5, 48.9];
15    let lon: Vec<f64> = vec![13.4, 2.3];
16
17    let red = Color::new(true, 255, 0, 0, 255);
18    let white = Color::new(true, 255, 255, 255, 255);
19
20    let line = LineBuilder::new()
21        .lat_coordinates(lat.into_iter().copied())
22        .lon_coordinates(lon.clone())
23        .width(3.)
24        .simplify(true)
25        .color(red)
26        .build()?;
27
28    let underline = LineBuilder::new()
29        .lat_coordinates(lat.into_iter().copied())
30        .lon_coordinates(lon)
31        .width(5.)
32        .simplify(true)
33        .color(white)
34        .build()?;
35
36    map.add_tool(underline);
37    map.add_tool(line);
38
39    map.save_png("line.png")?;
40
41    Ok(())
42}
Source

pub fn zoom(self, zoom: u8) -> Self

Map zoom, usually between 1-17. Determined based on map features if not specified.

Examples found in repository?
examples/empty_map.rs (line 7)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(300)
6        .height(300)
7        .zoom(4)
8        .lon_center(4.)
9        .lat_center(54.)
10        .build()?;
11
12    map.save_png("empty_map.png")?;
13
14    Ok(())
15}
More examples
Hide additional examples
examples/circle.rs (line 11)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(200)
9        .height(200)
10        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
11        .zoom(5)
12        .build()?;
13
14    let circle_outline = CircleBuilder::new()
15        .lon_coordinate(10.)
16        .lat_coordinate(47.)
17        .color(Color::new(true, 255, 255, 255, 255))
18        .radius(9.)
19        .build()?;
20
21    let circle = CircleBuilder::new()
22        .lon_coordinate(10.)
23        .lat_coordinate(47.)
24        .color(Color::new(true, 0, 0, 255, 255))
25        .radius(6.)
26        .build()?;
27
28    map.add_tool(circle_outline);
29    map.add_tool(circle);
30
31    map.save_png("circle.png")?;
32
33    Ok(())
34}
examples/icon.rs (line 9)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(200)
6        .height(200)
7        .padding((80, 0))
8        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
9        .zoom(12)
10        .build()?;
11
12    let icon_flag = IconBuilder::new()
13        .lon_coordinate(6.63204)
14        .lat_coordinate(45.85378)
15        .x_offset(12.)
16        .y_offset(32.)
17        .path("examples/icons/icon-flag.png")?
18        .build()?;
19
20    let icon_factory = IconBuilder::new()
21        .lon_coordinate(6.6015)
22        .lat_coordinate(45.8485)
23        .x_offset(18.)
24        .y_offset(18.)
25        .path("examples/icons/icon-factory.png")?
26        .build()?;
27
28    map.add_tool(icon_flag);
29    map.add_tool(icon_factory);
30
31    map.save_png("icon.png")?;
32
33    Ok(())
34}
Source

pub fn lat_center(self, coordinate: f64) -> Self

Latitude center of the map. Determined based on map features if not specified.

Examples found in repository?
examples/empty_map.rs (line 9)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(300)
6        .height(300)
7        .zoom(4)
8        .lon_center(4.)
9        .lat_center(54.)
10        .build()?;
11
12    map.save_png("empty_map.png")?;
13
14    Ok(())
15}
Source

pub fn lon_center(self, coordinate: f64) -> Self

Longitude center of the map. Determined based on map features if not specified.

Examples found in repository?
examples/empty_map.rs (line 8)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(300)
6        .height(300)
7        .zoom(4)
8        .lon_center(4.)
9        .lat_center(54.)
10        .build()?;
11
12    map.save_png("empty_map.png")?;
13
14    Ok(())
15}
Source

pub fn url_template<I: Into<String>>(self, url_template: I) -> Self

URL template, e.g. “https://example.com/{z}/{x}/{y}.png”. Default is “https://a.tile.osm.org/{z}/{x}/{y}.png”.

Examples found in repository?
examples/circle.rs (line 10)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(200)
9        .height(200)
10        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
11        .zoom(5)
12        .build()?;
13
14    let circle_outline = CircleBuilder::new()
15        .lon_coordinate(10.)
16        .lat_coordinate(47.)
17        .color(Color::new(true, 255, 255, 255, 255))
18        .radius(9.)
19        .build()?;
20
21    let circle = CircleBuilder::new()
22        .lon_coordinate(10.)
23        .lat_coordinate(47.)
24        .color(Color::new(true, 0, 0, 255, 255))
25        .radius(6.)
26        .build()?;
27
28    map.add_tool(circle_outline);
29    map.add_tool(circle);
30
31    map.save_png("circle.png")?;
32
33    Ok(())
34}
More examples
Hide additional examples
examples/icon.rs (line 8)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(200)
6        .height(200)
7        .padding((80, 0))
8        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
9        .zoom(12)
10        .build()?;
11
12    let icon_flag = IconBuilder::new()
13        .lon_coordinate(6.63204)
14        .lat_coordinate(45.85378)
15        .x_offset(12.)
16        .y_offset(32.)
17        .path("examples/icons/icon-flag.png")?
18        .build()?;
19
20    let icon_factory = IconBuilder::new()
21        .lon_coordinate(6.6015)
22        .lat_coordinate(45.8485)
23        .x_offset(18.)
24        .y_offset(18.)
25        .path("examples/icons/icon-factory.png")?
26        .build()?;
27
28    map.add_tool(icon_flag);
29    map.add_tool(icon_factory);
30
31    map.save_png("icon.png")?;
32
33    Ok(())
34}
Source

pub fn tile_size(self, tile_size: u32) -> Self

Tile size, in pixels. Default is 256.

Source

pub fn build(self) -> Result<StaticMap, Error>

Consumes the builder.

Examples found in repository?
examples/empty_map.rs (line 10)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(300)
6        .height(300)
7        .zoom(4)
8        .lon_center(4.)
9        .lat_center(54.)
10        .build()?;
11
12    map.save_png("empty_map.png")?;
13
14    Ok(())
15}
More examples
Hide additional examples
examples/circle.rs (line 12)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(200)
9        .height(200)
10        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
11        .zoom(5)
12        .build()?;
13
14    let circle_outline = CircleBuilder::new()
15        .lon_coordinate(10.)
16        .lat_coordinate(47.)
17        .color(Color::new(true, 255, 255, 255, 255))
18        .radius(9.)
19        .build()?;
20
21    let circle = CircleBuilder::new()
22        .lon_coordinate(10.)
23        .lat_coordinate(47.)
24        .color(Color::new(true, 0, 0, 255, 255))
25        .radius(6.)
26        .build()?;
27
28    map.add_tool(circle_outline);
29    map.add_tool(circle);
30
31    map.save_png("circle.png")?;
32
33    Ok(())
34}
examples/icon.rs (line 10)
3fn main() -> Result<(), Error> {
4    let mut map = StaticMapBuilder::new()
5        .width(200)
6        .height(200)
7        .padding((80, 0))
8        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
9        .zoom(12)
10        .build()?;
11
12    let icon_flag = IconBuilder::new()
13        .lon_coordinate(6.63204)
14        .lat_coordinate(45.85378)
15        .x_offset(12.)
16        .y_offset(32.)
17        .path("examples/icons/icon-flag.png")?
18        .build()?;
19
20    let icon_factory = IconBuilder::new()
21        .lon_coordinate(6.6015)
22        .lat_coordinate(45.8485)
23        .x_offset(18.)
24        .y_offset(18.)
25        .path("examples/icons/icon-factory.png")?
26        .build()?;
27
28    map.add_tool(icon_flag);
29    map.add_tool(icon_factory);
30
31    map.save_png("icon.png")?;
32
33    Ok(())
34}
examples/line.rs (line 11)
6fn main() -> Result<(), Error> {
7    let mut map = StaticMapBuilder::new()
8        .width(300)
9        .height(400)
10        .padding((10, 0))
11        .build()
12        .unwrap();
13
14    let lat: &[f64] = &[52.5, 48.9];
15    let lon: Vec<f64> = vec![13.4, 2.3];
16
17    let red = Color::new(true, 255, 0, 0, 255);
18    let white = Color::new(true, 255, 255, 255, 255);
19
20    let line = LineBuilder::new()
21        .lat_coordinates(lat.into_iter().copied())
22        .lon_coordinates(lon.clone())
23        .width(3.)
24        .simplify(true)
25        .color(red)
26        .build()?;
27
28    let underline = LineBuilder::new()
29        .lat_coordinates(lat.into_iter().copied())
30        .lon_coordinates(lon)
31        .width(5.)
32        .simplify(true)
33        .color(white)
34        .build()?;
35
36    map.add_tool(underline);
37    map.add_tool(line);
38
39    map.save_png("line.png")?;
40
41    Ok(())
42}

Trait Implementations§

Source§

impl Default for StaticMapBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.