maplibre/legacy/layout/
symbol_feature.rs

1//! Translated from https://github.com/maplibre/maplibre-native/blob/4add9ea/src/mbgl/layout/symbol_feature.hpp
2
3use std::cmp::Ordering;
4
5use crate::legacy::{
6    geometry_tile_data::{FeatureType, GeometryCollection, Identifier, Value},
7    style_types::expression,
8    tagged_string::TaggedString,
9};
10
11// TODO: Actual feature data with properties
12/// maplibre/maplibre-native#4add9ea original name: VectorGeometryTileFeature
13#[derive(Clone)]
14pub struct VectorGeometryTileFeature {
15    pub geometry: GeometryCollection,
16}
17
18/// maplibre/maplibre-native#4add9ea original name: SymbolGeometryTileFeature
19#[derive(Clone)]
20pub struct SymbolGeometryTileFeature {
21    feature: Box<VectorGeometryTileFeature>,
22    pub geometry: GeometryCollection, // we need a mutable copy of the geometry for mergeLines()
23    pub formatted_text: Option<TaggedString>,
24    pub icon: Option<expression::Image>,
25    pub sort_key: f64,
26    pub index: usize,
27}
28
29impl PartialEq<Self> for SymbolGeometryTileFeature {
30    /// maplibre/maplibre-native#4add9ea original name: eq
31    fn eq(&self, other: &Self) -> bool {
32        self.sort_key.eq(&other.sort_key) // TODO is this correct?
33    }
34}
35
36impl PartialOrd for SymbolGeometryTileFeature {
37    /// maplibre/maplibre-native#4add9ea original name: partial_cmp
38    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
39        self.sort_key.partial_cmp(&other.sort_key)
40    }
41}
42
43impl SymbolGeometryTileFeature {
44    /// maplibre/maplibre-native#4add9ea original name: getType
45    pub fn get_type(&self) -> FeatureType {
46        //  todo!()
47        FeatureType::Point
48    }
49    /// maplibre/maplibre-native#4add9ea original name: getValue
50    pub fn get_value(&self, key: &str) -> Option<&Value> {
51        todo!()
52    }
53    /// maplibre/maplibre-native#4add9ea original name: getProperties
54    pub fn get_properties(&self) -> &serde_json::Value {
55        todo!()
56    }
57    /// maplibre/maplibre-native#4add9ea original name: getID
58    pub fn get_id(&self) -> Identifier {
59        todo!()
60    }
61    /// maplibre/maplibre-native#4add9ea original name: getGeometries
62    pub fn get_geometries(&self) -> &GeometryCollection {
63        todo!()
64    }
65}
66
67impl SymbolGeometryTileFeature {
68    /// maplibre/maplibre-native#4add9ea original name: new
69    pub fn new(feature: Box<VectorGeometryTileFeature>) -> Self {
70        Self {
71            geometry: feature.geometry.clone(), // we need a mutable copy of the geometry for mergeLines()
72            feature,
73            formatted_text: None,
74            icon: None,
75            sort_key: 0.0,
76            index: 0,
77        }
78    }
79}