photon_geocoding/data/
filter.rs1use std::fmt;
2
3use crate::{BoundingBox, LatLon};
4
5pub enum PhotonLayer {
6 House,
7 Street,
8 Locality,
9 District,
10 City,
11 County,
12 State,
13 Country,
14}
15
16impl fmt::Display for PhotonLayer {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Self::House => write!(f, "house"),
20 Self::Street => write!(f, "street"),
21 Self::Locality => write!(f, "locality"),
22 Self::District => write!(f, "district"),
23 Self::City => write!(f, "city"),
24 Self::County => write!(f, "county"),
25 Self::State => write!(f, "state"),
26 Self::Country => write!(f, "country"),
27 }
28 }
29}
30
31pub struct ForwardFilter {
34 pub location_bias: Option<LatLon>,
35 pub location_bias_zoom: Option<u64>,
36 pub location_bias_scale: Option<f64>,
37 pub bounding_box: Option<BoundingBox>,
38 pub limit: Option<u64>,
39 pub lang: Option<String>,
40 pub layer: Option<Vec<PhotonLayer>>,
41 pub additional_query: Option<Vec<(String, String)>>,
42}
43
44impl Default for ForwardFilter {
45 fn default() -> Self {
46 ForwardFilter {
47 location_bias: None,
48 location_bias_zoom: None,
49 location_bias_scale: None,
50 bounding_box: None,
51 limit: None,
52 lang: None,
53 layer: None,
54 additional_query: None,
55 }
56 }
57}
58
59impl ForwardFilter {
60 pub fn new() -> Self {
62 Self::default()
63 }
64
65 pub fn location_bias(mut self, coords: LatLon, zoom: Option<u64>, scale: Option<f64>) -> Self {
71 self.location_bias = Some(coords);
72 self.location_bias_zoom = zoom;
73 self.location_bias_scale = scale;
74 self
75 }
76
77 pub fn bounding_box(mut self, bbox: BoundingBox) -> Self {
79 self.bounding_box = Some(bbox);
80 self
81 }
82
83 pub fn limit(mut self, limit: u64) -> Self {
85 self.limit = Some(limit);
86 self
87 }
88
89 pub fn language(mut self, lang: &str) -> Self {
92 self.lang = Some(String::from(lang.to_lowercase()));
93 self
94 }
95
96 pub fn layer(mut self, layer: Vec<PhotonLayer>) -> Self {
98 self.layer = Some(layer);
99 self
100 }
101
102 pub fn additional_query(mut self, query: Vec<(&str, &str)>) -> Self {
104 self.additional_query = Some(
105 query
106 .iter()
107 .map(|(s, t)| (s.to_string(), t.to_string()))
108 .collect(),
109 );
110 self
111 }
112}
113
114pub struct ReverseFilter {
117 pub radius: Option<u64>,
118 pub limit: Option<u64>,
119 pub lang: Option<String>,
120 pub layer: Option<Vec<PhotonLayer>>,
121 pub additional_query: Option<Vec<(String, String)>>,
122}
123
124impl Default for ReverseFilter {
125 fn default() -> Self {
126 ReverseFilter {
127 radius: None,
128 limit: None,
129 lang: None,
130 layer: None,
131 additional_query: None,
132 }
133 }
134}
135
136impl ReverseFilter {
137 pub fn new() -> Self {
139 Self::default()
140 }
141
142 pub fn radius(mut self, radius: u64) -> Self {
143 self.radius = Some(radius);
144 self
145 }
146
147 pub fn limit(mut self, limit: u64) -> Self {
149 self.limit = Some(limit);
150 self
151 }
152
153 pub fn language(mut self, lang: &str) -> Self {
156 self.lang = Some(String::from(lang.to_lowercase()));
157 self
158 }
159
160 pub fn layer(mut self, layer: Vec<PhotonLayer>) -> Self {
162 self.layer = Some(layer);
163 self
164 }
165
166 pub fn additional_query(mut self, query: Vec<(&str, &str)>) -> Self {
168 self.additional_query = Some(
169 query
170 .iter()
171 .map(|(s, t)| (s.to_string(), t.to_string()))
172 .collect(),
173 );
174 self
175 }
176}