maplibre_native_ffi/generated/
map_projection.rs1use super::*;
3
4native_owner! {
5 pub struct MapProjectionHandle(mln_map_projection) dispose |raw| { unsafe { sys::mln_map_projection_release(raw) }; Ok(()) };
12 fn id;
14}
15
16impl MapProjectionHandle {
17 pub fn create(view: &MapView) -> Result<MapProjectionHandle> {
26 let mut call = Call::global();
27 crate::abi::validate_abi_version()?;
28 let mut out_projection = sys::mln_map_projection(0);
29 let view = call.reference(&view)?;
30 call.status(|_, out_diagnostic| unsafe {
31 sys::mln_map_projection_create(view, &mut out_projection, out_diagnostic)
32 })?;
33 Ok(MapProjectionHandle::adopt(out_projection)?)
34 }
35
36 pub fn get_camera(&self) -> Result<MapProjectionCameraResult> {
41 let mut call = self.inner.call();
42 let mut out_result: sys::mln_map_projection_camera_result = unsafe { std::mem::zeroed() };
43 out_result.size = std::mem::size_of::<sys::mln_map_projection_camera_result>() as _;
44 call.status(|projection, out_diagnostic| unsafe {
45 sys::mln_map_projection_get_camera(projection, &mut out_result, out_diagnostic)
46 })?;
47 Ok(unsafe { from_native(out_result) }?)
48 }
49
50 pub fn lat_lng_for_pixel(&self, point: ScreenPoint) -> Result<LatLng> {
57 let mut call = self.inner.call();
58 let mut out_coordinate: sys::mln_lat_lng = unsafe { std::mem::zeroed() };
59 let point = call.input(&point)?;
60 call.status(|projection, out_diagnostic| unsafe {
61 sys::mln_map_projection_lat_lng_for_pixel(
62 projection,
63 point,
64 &mut out_coordinate,
65 out_diagnostic,
66 )
67 })?;
68 Ok(unsafe { from_native(out_coordinate) }?)
69 }
70
71 pub fn lat_lng_for_pixel_unwrapped(&self, point: ScreenPoint) -> Result<LatLng> {
79 let mut call = self.inner.call();
80 let mut out_coordinate: sys::mln_lat_lng = unsafe { std::mem::zeroed() };
81 let point = call.input(&point)?;
82 call.status(|projection, out_diagnostic| unsafe {
83 sys::mln_map_projection_lat_lng_for_pixel_unwrapped(
84 projection,
85 point,
86 &mut out_coordinate,
87 out_diagnostic,
88 )
89 })?;
90 Ok(unsafe { from_native(out_coordinate) }?)
91 }
92
93 pub fn lat_lngs_for_pixels(&self, points: &[ScreenPoint]) -> Result<Vec<LatLng>> {
99 let mut call = self.inner.call();
100 let point_count = convert::count(points.len())?;
101 let mut out_coordinates: Vec<sys::mln_lat_lng> = (0..points.len())
102 .map(|_| unsafe { std::mem::zeroed() })
103 .collect();
104 let points = call.array(points)?;
105 call.status(|projection, out_diagnostic| unsafe {
106 sys::mln_map_projection_lat_lngs_for_pixels(
107 projection,
108 points,
109 point_count,
110 out_coordinates.as_mut_ptr(),
111 out_diagnostic,
112 )
113 })?;
114 Ok(out_coordinates
115 .into_iter()
116 .map(|item| Ok(unsafe { from_native(item) }?))
117 .collect::<Result<Vec<_>>>()?)
118 }
119
120 pub fn lat_lngs_for_pixels_unwrapped(&self, points: &[ScreenPoint]) -> Result<Vec<LatLng>> {
126 let mut call = self.inner.call();
127 let point_count = convert::count(points.len())?;
128 let mut out_coordinates: Vec<sys::mln_lat_lng> = (0..points.len())
129 .map(|_| unsafe { std::mem::zeroed() })
130 .collect();
131 let points = call.array(points)?;
132 call.status(|projection, out_diagnostic| unsafe {
133 sys::mln_map_projection_lat_lngs_for_pixels_unwrapped(
134 projection,
135 points,
136 point_count,
137 out_coordinates.as_mut_ptr(),
138 out_diagnostic,
139 )
140 })?;
141 Ok(out_coordinates
142 .into_iter()
143 .map(|item| Ok(unsafe { from_native(item) }?))
144 .collect::<Result<Vec<_>>>()?)
145 }
146
147 pub fn meters_per_pixel_at_latitude(&self, latitude: f64) -> Result<f64> {
155 let mut call = self.inner.call();
156 let mut out_meters_per_pixel: f64 = Default::default();
157 call.status(|projection, out_diagnostic| unsafe {
158 sys::mln_map_projection_meters_per_pixel_at_latitude(
159 projection,
160 latitude,
161 &mut out_meters_per_pixel,
162 out_diagnostic,
163 )
164 })?;
165 Ok(out_meters_per_pixel)
166 }
167
168 pub fn pixel_for_lat_lng(&self, coordinate: LatLng) -> Result<ScreenPoint> {
175 let mut call = self.inner.call();
176 let mut out_point: sys::mln_screen_point = unsafe { std::mem::zeroed() };
177 let coordinate = call.input(&coordinate)?;
178 call.status(|projection, out_diagnostic| unsafe {
179 sys::mln_map_projection_pixel_for_lat_lng(
180 projection,
181 coordinate,
182 &mut out_point,
183 out_diagnostic,
184 )
185 })?;
186 Ok(unsafe { from_native(out_point) }?)
187 }
188
189 pub fn pixels_for_lat_lngs(&self, coordinates: &[LatLng]) -> Result<Vec<ScreenPoint>> {
195 let mut call = self.inner.call();
196 let coordinate_count = convert::count(coordinates.len())?;
197 let mut out_points: Vec<sys::mln_screen_point> = (0..coordinates.len())
198 .map(|_| unsafe { std::mem::zeroed() })
199 .collect();
200 let coordinates = call.array(coordinates)?;
201 call.status(|projection, out_diagnostic| unsafe {
202 sys::mln_map_projection_pixels_for_lat_lngs(
203 projection,
204 coordinates,
205 coordinate_count,
206 out_points.as_mut_ptr(),
207 out_diagnostic,
208 )
209 })?;
210 Ok(out_points
211 .into_iter()
212 .map(|item| Ok(unsafe { from_native(item) }?))
213 .collect::<Result<Vec<_>>>()?)
214 }
215
216 pub fn release(self) -> std::result::Result<(), ReleaseError<Self>> {
221 self.consume(|projection| {
222 let mut call = Call::new(projection);
223 call.run(|projection| unsafe { sys::mln_map_projection_release(projection) });
224 Ok(())
225 })
226 }
227
228 pub fn set_camera(&self, camera: &CameraOptions) -> Result<()> {
235 let mut call = self.inner.call();
236 let camera = call.reference(&camera)?;
237 call.status(|projection, out_diagnostic| unsafe {
238 sys::mln_map_projection_set_camera(projection, camera, out_diagnostic)
239 })?;
240 Ok(())
241 }
242}