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
impl StaticMap
Sourcepub fn add_tool(&mut self, tool: impl Tool + 'static)
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)
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
examples/icon.rs (line 28)
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 36)
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}
Sourcepub fn encode_png(&mut self) -> Result<Vec<u8>, Error>
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.
Sourcepub fn save_png<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error>
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)
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
examples/circle.rs (line 31)
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 31)
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 39)
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}
Auto Trait Implementations§
impl Freeze for StaticMap
impl !RefUnwindSafe for StaticMap
impl !Send for StaticMap
impl !Sync for StaticMap
impl Unpin for StaticMap
impl !UnwindSafe for StaticMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more