Struct staticmap::StaticMap

source ·
pub struct StaticMap { /* private fields */ }
Expand description

Main type. Use StaticMapBuilder as an entrypoint.

§Example

use staticmap::StaticMapBuilder;

let mut map = StaticMapBuilder::new()
    .width(300)
    .height(300)
    .zoom(4)
    .lat_center(52.6)
    .lon_center(13.4)
    .build()
    .unwrap();

Implementations§

source§

impl StaticMap

source

pub fn add_tool(&mut self, tool: impl Tool + 'static)

Add a type implementing Tool. The map can contain several tools.

Examples found in repository?
examples/circle.rs (line 28)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<(), Error> {
    let mut map = StaticMapBuilder::new()
        .width(200)
        .height(200)
        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
        .zoom(5)
        .build()?;

    let circle_outline = CircleBuilder::new()
        .lon_coordinate(10.)
        .lat_coordinate(47.)
        .color(Color::new(true, 255, 255, 255, 255))
        .radius(9.)
        .build()?;

    let circle = CircleBuilder::new()
        .lon_coordinate(10.)
        .lat_coordinate(47.)
        .color(Color::new(true, 0, 0, 255, 255))
        .radius(6.)
        .build()?;

    map.add_tool(circle_outline);
    map.add_tool(circle);

    map.save_png("circle.png")?;

    Ok(())
}
More examples
Hide additional examples
examples/icon.rs (line 28)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<(), Error> {
    let mut map = StaticMapBuilder::new()
        .width(200)
        .height(200)
        .padding((80, 0))
        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
        .zoom(12)
        .build()?;

    let icon_flag = IconBuilder::new()
        .lon_coordinate(6.63204)
        .lat_coordinate(45.85378)
        .x_offset(12.)
        .y_offset(32.)
        .path("examples/icons/icon-flag.png")?
        .build()?;

    let icon_factory = IconBuilder::new()
        .lon_coordinate(6.6015)
        .lat_coordinate(45.8485)
        .x_offset(18.)
        .y_offset(18.)
        .path("examples/icons/icon-factory.png")?
        .build()?;

    map.add_tool(icon_flag);
    map.add_tool(icon_factory);

    map.save_png("icon.png")?;

    Ok(())
}
examples/line.rs (line 36)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Error> {
    let mut map = StaticMapBuilder::new()
        .width(300)
        .height(400)
        .padding((10, 0))
        .build()
        .unwrap();

    let lat: &[f64] = &[52.5, 48.9];
    let lon: Vec<f64> = vec![13.4, 2.3];

    let red = Color::new(true, 255, 0, 0, 255);
    let white = Color::new(true, 255, 255, 255, 255);

    let line = LineBuilder::new()
        .lat_coordinates(lat.into_iter().copied())
        .lon_coordinates(lon.clone())
        .width(3.)
        .simplify(true)
        .color(red)
        .build()?;

    let underline = LineBuilder::new()
        .lat_coordinates(lat.into_iter().copied())
        .lon_coordinates(lon)
        .width(5.)
        .simplify(true)
        .color(white)
        .build()?;

    map.add_tool(underline);
    map.add_tool(line);

    map.save_png("line.png")?;

    Ok(())
}
source

pub fn encode_png(&mut self) -> Result<Vec<u8>, Error>

Render the map and encode as PNG.

May panic if any feature has invalid bounds.

source

pub fn save_png<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error>

Render the map and save as PNG to a file.

May panic if any feature has invalid bounds.

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

    map.save_png("empty_map.png")?;

    Ok(())
}
More examples
Hide additional examples
examples/circle.rs (line 31)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<(), Error> {
    let mut map = StaticMapBuilder::new()
        .width(200)
        .height(200)
        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
        .zoom(5)
        .build()?;

    let circle_outline = CircleBuilder::new()
        .lon_coordinate(10.)
        .lat_coordinate(47.)
        .color(Color::new(true, 255, 255, 255, 255))
        .radius(9.)
        .build()?;

    let circle = CircleBuilder::new()
        .lon_coordinate(10.)
        .lat_coordinate(47.)
        .color(Color::new(true, 0, 0, 255, 255))
        .radius(6.)
        .build()?;

    map.add_tool(circle_outline);
    map.add_tool(circle);

    map.save_png("circle.png")?;

    Ok(())
}
examples/icon.rs (line 31)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<(), Error> {
    let mut map = StaticMapBuilder::new()
        .width(200)
        .height(200)
        .padding((80, 0))
        .url_template("https://a.tile.osm.org/{z}/{x}/{y}.png")
        .zoom(12)
        .build()?;

    let icon_flag = IconBuilder::new()
        .lon_coordinate(6.63204)
        .lat_coordinate(45.85378)
        .x_offset(12.)
        .y_offset(32.)
        .path("examples/icons/icon-flag.png")?
        .build()?;

    let icon_factory = IconBuilder::new()
        .lon_coordinate(6.6015)
        .lat_coordinate(45.8485)
        .x_offset(18.)
        .y_offset(18.)
        .path("examples/icons/icon-factory.png")?
        .build()?;

    map.add_tool(icon_flag);
    map.add_tool(icon_factory);

    map.save_png("icon.png")?;

    Ok(())
}
examples/line.rs (line 39)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Error> {
    let mut map = StaticMapBuilder::new()
        .width(300)
        .height(400)
        .padding((10, 0))
        .build()
        .unwrap();

    let lat: &[f64] = &[52.5, 48.9];
    let lon: Vec<f64> = vec![13.4, 2.3];

    let red = Color::new(true, 255, 0, 0, 255);
    let white = Color::new(true, 255, 255, 255, 255);

    let line = LineBuilder::new()
        .lat_coordinates(lat.into_iter().copied())
        .lon_coordinates(lon.clone())
        .width(3.)
        .simplify(true)
        .color(red)
        .build()?;

    let underline = LineBuilder::new()
        .lat_coordinates(lat.into_iter().copied())
        .lon_coordinates(lon)
        .width(5.)
        .simplify(true)
        .color(white)
        .build()?;

    map.add_tool(underline);
    map.add_tool(line);

    map.save_png("line.png")?;

    Ok(())
}

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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>,

§

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>,

§

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.