use std::borrow::Cow;
use feature::{Identifier, PropertyMap, Value};
use mln_style::expression::image::Image;
use mln_style::feature::{GeometryCollection, GeometryTileFeature};
use mln_style::geometry::FeatureType;
use crate::text::TaggedString;
#[derive(Clone, Debug)]
pub(crate) struct SymbolFeature {
feature_type: FeatureType,
id: Identifier,
properties: PropertyMap,
original_geometry: GeometryCollection,
pub(crate) geometry: GeometryCollection,
pub(crate) formatted_text: Option<TaggedString>,
pub(crate) icon: Option<Image>,
pub(crate) sort_key: f32,
pub(crate) index: usize,
}
impl SymbolFeature {
pub(crate) fn new(feature: &dyn GeometryTileFeature, geometry: GeometryCollection) -> Self {
SymbolFeature {
feature_type: feature.get_type(),
id: feature.get_id(),
properties: feature.get_properties().into_owned(),
original_geometry: geometry.clone(),
geometry,
formatted_text: None,
icon: None,
sort_key: 0.0,
index: 0,
}
}
}
impl GeometryTileFeature for SymbolFeature {
fn get_type(&self) -> FeatureType {
self.feature_type
}
fn get_value(&self, key: &str) -> Option<Value> {
self.properties.get(key).cloned()
}
fn get_properties(&self) -> Cow<'_, PropertyMap> {
Cow::Borrowed(&self.properties)
}
fn get_id(&self) -> Identifier {
self.id.clone()
}
fn get_geometries(&self) -> Result<Cow<'_, GeometryCollection>, mln_style::error::Error> {
Ok(Cow::Borrowed(&self.original_geometry))
}
}