1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)]
7pub struct LatLng {
8 pub lat: f64,
10 pub lng: f64,
12}
13
14impl LatLng {
15 pub fn new(lat: f64, lng: f64) -> Self {
17 Self { lat, lng }
18 }
19
20 pub fn helsinki() -> Self {
22 Self::new(60.1699, 24.9384)
23 }
24
25 pub fn to_array(&self) -> [f64; 2] {
27 [self.lng, self.lat]
28 }
29
30 pub fn from_array(arr: [f64; 2]) -> Self {
32 Self {
33 lng: arr[0],
34 lat: arr[1],
35 }
36 }
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
41pub struct MapPosition {
42 pub center: LatLng,
44 pub zoom: f64,
46}
47
48impl MapPosition {
49 pub fn new(center: LatLng, zoom: f64) -> Self {
50 Self { center, zoom }
51 }
52}
53
54impl Default for MapPosition {
55 fn default() -> Self {
56 Self {
57 center: LatLng::helsinki(),
58 zoom: 10.0,
59 }
60 }
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
65pub struct Bounds {
66 pub sw: LatLng,
68 pub ne: LatLng,
70}
71
72impl Bounds {
73 pub fn new(sw: LatLng, ne: LatLng) -> Self {
74 Self { sw, ne }
75 }
76
77 pub fn contains(&self, point: &LatLng) -> bool {
79 point.lat >= self.sw.lat
80 && point.lat <= self.ne.lat
81 && point.lng >= self.sw.lng
82 && point.lng <= self.ne.lng
83 }
84
85 pub fn center(&self) -> LatLng {
87 LatLng {
88 lat: f64::midpoint(self.sw.lat, self.ne.lat),
89 lng: f64::midpoint(self.sw.lng, self.ne.lng),
90 }
91 }
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(rename_all = "camelCase")]
97pub struct QueryFeature {
98 #[serde(default)]
100 pub id: Option<i64>,
101 pub geometry: serde_json::Value,
103 pub properties: serde_json::Value,
105 pub source: String,
107 #[serde(default)]
109 pub source_layer: Option<String>,
110}
111
112#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)]
114pub struct Point {
115 pub x: f64,
117 pub y: f64,
119}
120
121impl Point {
122 pub fn new(x: f64, y: f64) -> Self {
123 Self { x, y }
124 }
125}