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)
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 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(())
}
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)
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 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§
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