cartography 0.10.0

Cartography is a map rendering library for Geographic features expressed using [georust](https://georust.org/) libraries.
Documentation
#![doc = include_str!("../README.MD")]
#![warn(missing_docs)]

#[cfg(feature = "egui")]
pub mod egui;
#[cfg(feature = "geojson")]
pub mod geojson;
mod geometry;
mod image;
mod layer;
mod map;
#[cfg(feature = "osm")]
pub mod osm;
mod projection;
mod renderer;
#[cfg(feature = "style-yaml")]
pub mod style_yaml;
mod styling;
#[cfg(feature = "tiles")]
mod tiles;
#[cfg(feature = "vello")]
pub mod vello;
#[cfg(feature = "xilem")]
pub mod xilem;

pub use geo;

pub use anyhow::Result;

pub use ccutils::containers::RefOrValue;
#[cfg(feature = "tiles")]
pub use tiles_client::ClientBuilder as TilesClientBuilder;

pub(crate) use layer::BoxedLayer;
pub(crate) use projection::YAxisDirection;

pub use geometry::GeometryType;
pub use image::{BoxedImageDataRef, ImageData, ImageFeature, VecLayer as ImagesVecLayer};
pub use layer::{FeaturesVecLayer, IntoLayer, Layer};
pub use map::{Feature, GeometryRef, Map, MapBuilder};
pub use projection::{Projection, Unit as ProjectionUnit, transform};
pub use styling::{LabelConfig, Rgba, Style, StyleBuilder, Symbol, SymbolColor, rgb, rgba};
#[cfg(feature = "tiles")]
pub use tiles::{Tile, TilesLayer};

#[cfg(feature = "image")]
pub use image::{GeoImage, load_image_from_memory, open_image};

/// Utility module
pub mod utils
{
  /// Convenient macro to generate the TryInto for references needed to cast a Feature to a child.
  /// For example:
  /// ```
  /// struct City;
  /// struct Country;
  ///
  /// #[enum_dispatch::enum_dispatch(FeatureTrait)]
  /// pub enum Feature
  /// {
  ///   City,
  ///   Country,
  /// }
  ///
  /// cartography::utils::try_from_feature!(City, Feature);
  ///
  /// ```
  #[macro_export]
  macro_rules! try_from_feature {
    ($child: tt, $feature: tt) => {
      impl<'a> TryFrom<&'a $feature> for &'a $child
      {
        type Error = &'static str;
        fn try_from(feature: &'a $feature) -> Result<Self, Self::Error>
        {
          match feature
          {
            $feature::$child(v) => Ok(v),
            _ => Err("Invalid feature type."),
          }
        }
      }
    };
  }
  pub use try_from_feature;

  /// Sometime it is desirable to compose different type of Feature in an enum.
  /// This macro allows to define such a composite feature. It will automatically
  /// generate an implementation of the Feature trait that dispatch to the values.
  /// as well as generate From and TryFrom traits.
  ///
  /// For example:
  /// ```ignore
  /// # // This example requires the `image` and `geojson` features to be enabled
  /// cartography::utils::composite_feature!(
  ///   enum MyFeature {
  ///     Image(cartography::ImageFeature<cartography::GeoImage>),
  ///     GeoJsonFeature(geojson::Feature),
  ///   }
  /// );
  /// ```
  #[macro_export]
  macro_rules! composite_feature {
    (enum $feature: ident { $($children: ident($children_ty: ty)),* $(,)? }) => {
      enum $feature
      {
        $(
          $children($children_ty),
        )*
      }
      $(
        impl From<$children_ty> for $feature
        {
          fn from(value: $children_ty) -> Self
          {
            Self::$children(value)
          }
        }
        impl<'a> TryFrom<&'a $feature> for &'a $children_ty
        {
          type Error = &'static str;
          fn try_from(feature: &'a $feature) -> Result<Self, Self::Error>
          {
            match feature
            {
              $feature::$children(v) => Ok(v),
              _ => Err("Invalid feature type."),
            }
          }
        }
      )*
      impl $crate::Feature for $feature
      {
        fn element_geometry_type(&self) -> cartography::GeometryType
        {
          match self
          {
            $(
              $feature::$children(feat) => feat.element_geometry_type(),
            )*
          }
        }
        fn geometry(&self) -> Option<cartography::geo::Geometry>
        {
          match self
          {
            $(
              $feature::$children(feat) => feat.geometry(),
            )*
          }
        }
        fn geometry_type(&self) -> cartography::GeometryType
        {
          match self
          {
            $(
              $feature::$children(feat) => feat.geometry_type(),
            )*
          }
        }
        fn image<'a>(&'a self) -> Option<cartography::ImageFeature<cartography::BoxedImageDataRef<'a>>>
        {
          match self
          {
            $(
              $feature::$children(feat) => feat.image(),
            )*
          }
        }
        fn intersects(&self, rect: cartography::geo::Rect) -> bool
        {
          match self
          {
            $(
              $feature::$children(feat) => feat.intersects(rect),
            )*
          }
        }
      }
    };
  }
  pub use composite_feature;
}