Struct staticmap::StaticMapBuilder
source · pub struct StaticMapBuilder { /* private fields */ }
Expand description
Builder for StaticMap.
Implementations§
source§impl StaticMapBuilder
impl StaticMapBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with defaults.
Examples found in repository?
examples/empty_map.rs (line 4)
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
examples/circle.rs (line 7)
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 4)
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 7)
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(())
}
sourcepub fn width(self, width: u32) -> Self
pub fn width(self, width: u32) -> Self
Image width, in pixels. Default is 300.
Examples found in repository?
examples/empty_map.rs (line 5)
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
examples/circle.rs (line 8)
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 5)
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 8)
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(())
}
sourcepub fn height(self, height: u32) -> Self
pub fn height(self, height: u32) -> Self
Image height, in pixels. Default is 300.
Examples found in repository?
examples/empty_map.rs (line 6)
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
examples/circle.rs (line 9)
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 6)
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 9)
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(())
}
sourcepub fn padding(self, padding: (u32, u32)) -> Self
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)
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(())
}
More examples
examples/line.rs (line 10)
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(())
}
sourcepub fn zoom(self, zoom: u8) -> Self
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)
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
examples/circle.rs (line 11)
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 9)
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(())
}
sourcepub fn lat_center(self, coordinate: f64) -> Self
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)
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(())
}
sourcepub fn lon_center(self, coordinate: f64) -> Self
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)
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(())
}
sourcepub fn url_template<I: Into<String>>(self, url_template: I) -> Self
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)
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
examples/icon.rs (line 8)
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(())
}
sourcepub fn build(self) -> Result<StaticMap, Error>
pub fn build(self) -> Result<StaticMap, Error>
Consumes the builder.
Examples found in repository?
examples/empty_map.rs (line 10)
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
examples/circle.rs (line 12)
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 10)
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 11)
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(())
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for StaticMapBuilder
impl Send for StaticMapBuilder
impl Sync for StaticMapBuilder
impl Unpin for StaticMapBuilder
impl UnwindSafe for StaticMapBuilder
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