A simple map viewer

projection.rs 706B

12345678910111213141516171819202122232425262728293031
  1. use std::str::FromStr;
  2. #[derive(Clone, Copy, Debug, Eq, PartialEq)]
  3. pub enum Projection {
  4. // EPSG:3857: WGS 84 / Pseudo-Mercator
  5. Mercator,
  6. // Orthographic projection, WGS 84 coordinates mapped to the sphere
  7. Orthografic,
  8. }
  9. impl Projection {
  10. pub fn to_str(&self) -> &str {
  11. match *self {
  12. Projection::Mercator => "mercator",
  13. Projection::Orthografic => "orthografic",
  14. }
  15. }
  16. }
  17. impl FromStr for Projection {
  18. type Err = ();
  19. fn from_str(s: &str) -> Result<Self, ()> {
  20. match s {
  21. "mercator" => Ok(Projection::Mercator),
  22. "orthografic" => Ok(Projection::Orthografic),
  23. _ => Err(()),
  24. }
  25. }
  26. }