maplibre_native_ffi/generated/map.rs
1// Generated from C headers by tools/bindgen. Do not edit.
2use super::*;
3
4native_owner! {
5 /// Owns one native handle.
6 ///
7 /// A map, with its style and camera.
8 ///
9 /// See `mln_map` in the
10 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
11 pub struct MapHandle(mln_map) dispose |raw| crate::error::check(|out_diagnostic| unsafe { sys::mln_map_dispose(raw, out_diagnostic) });
12 /// Returns the native handle value, which runtime events report as their source.
13 fn id;
14}
15
16impl MapHandle {
17 /// Adds a source whose GeoJSON tiles come from callbacks.
18 ///
19 /// See `mln_map_add_custom_geometry_source` in the
20 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
21 ///
22 /// # Errors
23 ///
24 /// - `Status::AlreadyExists` when the style already has a source named
25 /// `source_id`.
26 /// - `Status::InvalidState` while the style isn't loaded, as
27 /// `MapHandle::set_style_url()` describes.
28 pub fn add_custom_geometry_source(
29 &self,
30 source_id: &str,
31 options: CustomGeometrySourceOptions,
32 ) -> Result<NativeFuture<CommandCompletion>> {
33 let mut call = self.inner.call();
34 let source_id = call.input(&source_id)?;
35 let options = call.reference(&options)?;
36 call.command(|map, completion, out_diagnostic| unsafe {
37 sys::mln_map_add_custom_geometry_source(
38 map,
39 source_id,
40 options,
41 completion,
42 out_diagnostic,
43 )
44 })
45 }
46
47 /// Adds a source whose vector tiles come from callbacks.
48 ///
49 /// See `mln_map_add_custom_vector_source` in the
50 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
51 ///
52 /// # Errors
53 ///
54 /// - `Status::AlreadyExists` when the style already has a source named
55 /// `source_id`.
56 /// - `Status::InvalidState` while the style isn't loaded, as
57 /// `MapHandle::set_style_url()` describes.
58 pub fn add_custom_vector_source(
59 &self,
60 source_id: &str,
61 options: CustomVectorSourceOptions,
62 ) -> Result<NativeFuture<CommandCompletion>> {
63 let mut call = self.inner.call();
64 let source_id = call.input(&source_id)?;
65 let options = call.reference(&options)?;
66 call.command(|map, completion, out_diagnostic| unsafe {
67 sys::mln_map_add_custom_vector_source(
68 map,
69 source_id,
70 options,
71 completion,
72 out_diagnostic,
73 )
74 })
75 }
76
77 /// Adds a GeoJSON source with no data.
78 ///
79 /// Give it data with `MapHandle::set_geo_json_source_data()` or
80 /// `MapHandle::set_geo_json_source_url()`. Its options stay fixed for as
81 /// long as the style holds it.
82 ///
83 /// `attribution` is the source's
84 /// \[attribution\](https://maplibre.org/maplibre-style-spec/sources/#attribution),
85 /// or empty for none.
86 ///
87 /// See `mln_map_add_geo_json_source` in the
88 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
89 ///
90 /// # Errors
91 ///
92 /// - `Status::InvalidArgument` when an option in `options` is out of range.
93 /// - `Status::AlreadyExists` when the style already has a source named
94 /// `source_id`.
95 /// - `Status::InvalidState` while the style isn't loaded, as
96 /// `MapHandle::set_style_url()` describes.
97 pub fn add_geo_json_source(
98 &self,
99 source_id: &str,
100 options: Option<&GeoJsonSourceOptions>,
101 attribution: Option<&str>,
102 ) -> Result<NativeFuture<CommandCompletion>> {
103 let mut call = self.inner.call();
104 let source_id = call.input(&source_id)?;
105 let options = call.optional_reference(options.as_ref())?;
106 let attribution = call.input(&attribution)?;
107 call.command(|map, completion, out_diagnostic| unsafe {
108 sys::mln_map_add_geo_json_source(
109 map,
110 source_id,
111 options,
112 attribution,
113 completion,
114 out_diagnostic,
115 )
116 })
117 }
118
119 /// Adds an image source that shows `image`.
120 ///
121 /// `coordinates` are the image's four corners, clockwise from the top left.
122 ///
123 /// See `mln_map_add_image_source_image` in the
124 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
125 ///
126 /// # Errors
127 ///
128 /// - `Status::AlreadyExists` when the style already has a source named
129 /// `source_id`.
130 /// - `Status::InvalidState` while the style isn't loaded, as
131 /// `MapHandle::set_style_url()` describes.
132 pub fn add_image_source_image(
133 &self,
134 source_id: &str,
135 coordinates: &[LatLng],
136 image: &PremultipliedRgba8Image<'_>,
137 ) -> Result<NativeFuture<CommandCompletion>> {
138 let mut call = self.inner.call();
139 let coordinate_count = convert::count(coordinates.len())?;
140 let source_id = call.input(&source_id)?;
141 let coordinates = call.array(coordinates)?;
142 let image = call.reference(&image)?;
143 call.command(|map, completion, out_diagnostic| unsafe {
144 sys::mln_map_add_image_source_image(
145 map,
146 source_id,
147 coordinates,
148 coordinate_count,
149 image,
150 completion,
151 out_diagnostic,
152 )
153 })
154 }
155
156 /// Adds a layer to the map's style.
157 ///
158 /// `layer_json` is a
159 /// \[layer\](https://maplibre.org/maplibre-style-spec/layers/) object. The
160 /// layer goes below the layer named `before_layer_id`, or above every layer
161 /// when `before_layer_id` is empty.
162 ///
163 /// See `mln_map_add_style_layer_json` in the
164 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
165 ///
166 /// # Errors
167 ///
168 /// - `Status::NotFound` when the style has no layer named
169 /// `before_layer_id`, or no source with the ID that the layer uses.
170 /// - `Status::AlreadyExists` when the style already has a layer with the
171 /// new layer's ID.
172 /// - `Status::InvalidState` while the style isn't loaded, as
173 /// `MapHandle::set_style_url()` describes.
174 pub fn add_style_layer_json(
175 &self,
176 layer_json: &str,
177 before_layer_id: Option<&str>,
178 ) -> Result<NativeFuture<CommandCompletion>> {
179 let mut call = self.inner.call();
180 let layer_json = call.input(&layer_json)?;
181 let before_layer_id = call.input(&before_layer_id)?;
182 call.command(|map, completion, out_diagnostic| unsafe {
183 sys::mln_map_add_style_layer_json(
184 map,
185 layer_json,
186 before_layer_id,
187 completion,
188 out_diagnostic,
189 )
190 })
191 }
192
193 /// Adds a source to the map's style.
194 ///
195 /// `source_json` is a
196 /// \[source\](https://maplibre.org/maplibre-style-spec/sources/) object.
197 ///
198 /// See `mln_map_add_style_source_json` in the
199 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
200 ///
201 /// # Errors
202 ///
203 /// - `Status::AlreadyExists` when the style already has a source named
204 /// `source_id`.
205 /// - `Status::InvalidState` while the style isn't loaded, as
206 /// `MapHandle::set_style_url()` describes.
207 pub fn add_style_source_json(
208 &self,
209 source_id: &str,
210 source_json: &str,
211 ) -> Result<NativeFuture<CommandCompletion>> {
212 let mut call = self.inner.call();
213 let source_id = call.input(&source_id)?;
214 let source_json = call.input(&source_json)?;
215 call.command(|map, completion, out_diagnostic| unsafe {
216 sys::mln_map_add_style_source_json(
217 map,
218 source_id,
219 source_json,
220 completion,
221 out_diagnostic,
222 )
223 })
224 }
225
226 /// Moves the camera relative to where it is, as a gesture does.
227 ///
228 /// `delta` can pan the map's content by an offset on the screen, scale the
229 /// zoom, and add to the bearing and pitch. An anchor keeps one screen point
230 /// in place while the scale, bearing, or pitch changes. An anchor needs one
231 /// of those changes, and combines with an offset only when the delta has no
232 /// animation. The function finishes when the map applies the delta, before
233 /// an animation ends.
234 ///
235 /// A delta that replaces an animated one starts from where that animation
236 /// left the camera, so the rest of the replaced change never happens. To
237 /// reach an exact camera, use `MapHandle::update_camera()`.
238 ///
239 /// A delta in the end phase can carry momentum, which keeps the camera
240 /// moving from the gesture's release velocities and slows it on each
241 /// rendered frame. The gesture lasts until the momentum ends: the snapshot
242 /// keeps `gesture_in_progress` set, and camera events report
243 /// `CameraChangeSource::Momentum`. With momentum, `animation` sets only
244 /// `transition_id` and the end handler, which runs when the gesture ends.
245 ///
246 /// A delta in the begin phase, `MapHandle::cancel_camera_transitions()`, or
247 /// a cancellation by that ID stops the momentum. A later command that sets
248 /// a field stops only the parts of the momentum that move that field. On a
249 /// tilted map, the pan moves the map's content the same distance on the
250 /// screen in every direction.
251 ///
252 /// See `mln_map_apply_camera_delta` in the
253 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
254 pub fn apply_camera_delta(
255 &self,
256 delta: &CameraDelta,
257 ) -> Result<NativeFuture<CommandCompletion>> {
258 let mut call = self.inner.call();
259 let delta = call.reference(&delta)?;
260 call.command(|map, completion, out_diagnostic| unsafe {
261 sys::mln_map_apply_camera_delta(map, delta, completion, out_diagnostic)
262 })
263 }
264
265 /// Creates a session that renders the map into a ring of Android hardware
266 /// buffers that the library allocates.
267 ///
268 /// Acquire each frame with `RenderSessionHandle::acquire_frame()`, and get
269 /// its buffer with `AcquiredFrameView::get_android_hardware_buffer()`.
270 /// `RenderSessionHandle::resize()` gives the ring new buffers of the new
271 /// size.
272 ///
273 /// A Vulkan build renders with `device`, or, when `device` is null, with a
274 /// device that the library creates. An OpenGL build uses an EGL context on
275 /// the default display, and `device` must be null. Attach with
276 /// `RenderDriverKind::CoreWorker`.
277 ///
278 /// To show the buffers through Android's UI, such as with
279 /// `Bitmap.wrapHardwareBuffer`, attach without `GpuSyncKindFlag::SYNC_FD`
280 /// in `RenderSessionAttachOptions::producer_sync_kinds`, so that each frame
281 /// finishes before you acquire it. Keep each frame acquired until the next
282 /// one replaces it on screen, then release it with
283 /// `GpuSyncKind::CpuComplete`. Give the ring 3 buffers, so the session can
284 /// render while you hold two frames.
285 ///
286 /// See `mln_map_attach_android_hardware_buffer_ring` in the
287 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/android_8h.html).
288 ///
289 /// # Errors
290 ///
291 /// - `Status::Unsupported` when Android is older than 8.0, API level 26, or
292 /// when the graphics context can't render into hardware buffers: the
293 /// Vulkan device lacks
294 /// VK_ANDROID_external_memory_android_hardware_buffer, or the EGL display
295 /// lacks EGL_ANDROID_get_native_client_buffer or
296 /// EGL_ANDROID_image_native_buffer.
297 /// - `Status::NativeError` when the library can't create its Vulkan device
298 /// or initialize the default EGL display.
299 #[cfg(target_os = "android")]
300 pub fn attach_android_hardware_buffer_ring(
301 &self,
302 descriptor: &AndroidHardwareBufferRingDescriptor,
303 device: Option<&VulkanDeviceHandle>,
304 options: &RenderSessionAttachOptions,
305 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
306 let mut call = self.inner.call();
307 let device = device.map_or(sys::mln_vulkan_device(0), |device| device.inner.native());
308 let mut out_session = sys::mln_render_session(0);
309 let descriptor = call.reference(&descriptor)?;
310 let options = call.reference(&options)?;
311 let future = call.complete(
312 |map, completion, out_diagnostic| unsafe {
313 sys::mln_map_attach_android_hardware_buffer_ring(
314 map,
315 descriptor,
316 device,
317 options,
318 &mut out_session,
319 completion,
320 out_diagnostic,
321 )
322 },
323 completion::unit,
324 )?;
325 Ok((RenderSessionHandle::adopt(out_session)?, future))
326 }
327
328 /// Creates a session that presents the map to an Android window, with a
329 /// graphics context that the library creates.
330 ///
331 /// A Vulkan build presents with `device`, or, when `device` is null, with a
332 /// device that the library creates. An OpenGL build uses an EGL context on
333 /// the default display, and `device` must be null. Attach with
334 /// `RenderDriverKind::CoreWorker`.
335 ///
336 /// When the platform destroys the window, such as in
337 /// `SurfaceHolder.Callback.surfaceDestroyed`, release the target with
338 /// `RenderSessionHandle::release_target()`, or give the session a new
339 /// window with `RenderSessionHandle::set_android_surface_target()`, without
340 /// waiting for that to complete. The session keeps its own reference to the
341 /// window and stays usable for the next window. A frame to the destroyed
342 /// window finishes with `RenderResult::TargetNotReady`, or with
343 /// `RenderResult::Rendered` if the window went away while the frame was
344 /// presenting.
345 ///
346 /// See `mln_map_attach_android_surface` in the
347 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/android_8h.html).
348 ///
349 /// # Errors
350 ///
351 /// - `Status::InvalidArgument` when `surface` has no window, such as after
352 /// the platform destroyed it.
353 /// - `Status::Unsupported` when you created `device` without
354 /// `VulkanDeviceOptions::presentation`.
355 /// - `Status::Unsupported` when the GPU or the Vulkan loader can't present.
356 /// - `Status::NativeError` when the library can't create the graphics
357 /// context or the window's surface.
358 ///
359 /// # Safety
360 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
361 #[cfg(target_os = "android")]
362 pub unsafe fn attach_android_surface(
363 &self,
364 descriptor: &AndroidSurfaceDescriptor,
365 device: Option<&VulkanDeviceHandle>,
366 options: &RenderSessionAttachOptions,
367 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
368 let mut call = self.inner.call();
369 let device = device.map_or(sys::mln_vulkan_device(0), |device| device.inner.native());
370 let mut out_session = sys::mln_render_session(0);
371 let descriptor = call.reference(&descriptor)?;
372 let options = call.reference(&options)?;
373 let future = call.complete(
374 |map, completion, out_diagnostic| unsafe {
375 sys::mln_map_attach_android_surface(
376 map,
377 descriptor,
378 device,
379 options,
380 &mut out_session,
381 completion,
382 out_diagnostic,
383 )
384 },
385 completion::unit,
386 )?;
387 Ok((RenderSessionHandle::adopt(out_session)?, future))
388 }
389
390 /// Creates a session that renders the map into a ring of dmabufs that the
391 /// library allocates.
392 ///
393 /// Acquire each frame with `RenderSessionHandle::acquire_frame()`, and get
394 /// its buffer with `AcquiredFrameView::get_dma_buf()`.
395 /// `RenderSessionHandle::resize()` gives the ring new buffers of the new
396 /// size.
397 ///
398 /// A Vulkan build renders with `device`, or, when `device` is null, with a
399 /// device that the library creates. An OpenGL build uses an EGL context of
400 /// its own, and `device` must be null. Attach with
401 /// `RenderDriverKind::CoreWorker`.
402 ///
403 /// For a reader that waits on no sync file, such as a Wayland compositor
404 /// without explicit synchronization, attach without
405 /// `GpuSyncKindFlag::SYNC_FD` in
406 /// `RenderSessionAttachOptions::producer_sync_kinds`, so that each frame
407 /// finishes before you acquire it. Keep each frame acquired until its
408 /// reader is done with the buffer. Give the ring 3 buffers, so the session
409 /// can render while you hold two frames.
410 ///
411 /// See `mln_map_attach_dma_buf_ring` in the
412 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/linux_8h.html).
413 ///
414 /// # Errors
415 ///
416 /// - `Status::Unsupported` when the graphics context can't render into a
417 /// dmabuf of any of `formats`.
418 /// - `Status::NativeError` when the library can't create its Vulkan device
419 /// or initialize an EGL display.
420 #[cfg(any(
421 target_os = "freebsd",
422 all(target_os = "linux", not(target_env = "ohos"))
423 ))]
424 pub fn attach_dma_buf_ring(
425 &self,
426 descriptor: &DmaBufRingDescriptor,
427 device: Option<&VulkanDeviceHandle>,
428 options: &RenderSessionAttachOptions,
429 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
430 let mut call = self.inner.call();
431 let device = device.map_or(sys::mln_vulkan_device(0), |device| device.inner.native());
432 let mut out_session = sys::mln_render_session(0);
433 let descriptor = call.reference(&descriptor)?;
434 let options = call.reference(&options)?;
435 let future = call.complete(
436 |map, completion, out_diagnostic| unsafe {
437 sys::mln_map_attach_dma_buf_ring(
438 map,
439 descriptor,
440 device,
441 options,
442 &mut out_session,
443 completion,
444 out_diagnostic,
445 )
446 },
447 completion::unit,
448 )?;
449 Ok((RenderSessionHandle::adopt(out_session)?, future))
450 }
451
452 /// Creates a session that renders the map into a ring of DXGI shared
453 /// textures that the library allocates.
454 ///
455 /// Acquire each frame with `RenderSessionHandle::acquire_frame()`, and get
456 /// its texture with `AcquiredFrameView::get_dxgi_shared_texture()`.
457 /// `RenderSessionHandle::resize()` gives the ring new textures of the new
458 /// size.
459 ///
460 /// The session renders with the Vulkan device `device`, or, when `device`
461 /// is null, with one that the library creates. The textures belong to the
462 /// device's GPU, so open them on a D3D11 or D3D12 device of the same
463 /// adapter. To pick the GPU, create `device` with
464 /// `VulkanDeviceOptions::device_luid` set to your adapter's LUID. Attach
465 /// with `RenderDriverKind::CoreWorker`.
466 ///
467 /// For a reader that waits on no fence, such as Flutter's texture
468 /// registrar, attach without `GpuSyncKindFlag::D3D12_FENCE` in
469 /// `RenderSessionAttachOptions::producer_sync_kinds`, so that each frame
470 /// finishes before you acquire it. Release a frame with
471 /// `GpuSyncKind::CpuComplete` only once the reader has finished with its
472 /// texture.
473 ///
474 /// See `mln_map_attach_dxgi_shared_texture_ring` in the
475 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/win32_8h.html).
476 ///
477 /// # Errors
478 ///
479 /// - `Status::Unsupported` in an OpenGL build, or when the GPU can't share
480 /// the textures: D3D11 has no adapter with the Vulkan device's LUID or
481 /// can't share textures through NT handles, or the device lacks
482 /// VK_KHR_external_memory_win32 or can't import D3D11 textures.
483 /// - `Status::NativeError` when the library can't create its Vulkan device
484 /// or a D3D11 device on the adapter.
485 #[cfg(target_os = "windows")]
486 pub fn attach_dxgi_shared_texture_ring(
487 &self,
488 descriptor: &DxgiSharedTextureRingDescriptor,
489 device: Option<&VulkanDeviceHandle>,
490 options: &RenderSessionAttachOptions,
491 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
492 let mut call = self.inner.call();
493 let device = device.map_or(sys::mln_vulkan_device(0), |device| device.inner.native());
494 let mut out_session = sys::mln_render_session(0);
495 let descriptor = call.reference(&descriptor)?;
496 let options = call.reference(&options)?;
497 let future = call.complete(
498 |map, completion, out_diagnostic| unsafe {
499 sys::mln_map_attach_dxgi_shared_texture_ring(
500 map,
501 descriptor,
502 device,
503 options,
504 &mut out_session,
505 completion,
506 out_diagnostic,
507 )
508 },
509 completion::unit,
510 )?;
511 Ok((RenderSessionHandle::adopt(out_session)?, future))
512 }
513
514 /// Creates a session that renders the map into a ring of IOSurfaces that
515 /// the library allocates.
516 ///
517 /// Acquire each frame with `RenderSessionHandle::acquire_frame()`, and get
518 /// its surface with `AcquiredFrameView::get_io_surface()`.
519 /// `RenderSessionHandle::resize()` gives the ring new surfaces of the new
520 /// size. Attach with `RenderDriverKind::CoreWorker`.
521 ///
522 /// To hand frames to a reader that can't wait on an event, such as
523 /// Flutter's `copyPixelBuffer`, attach without
524 /// `GpuSyncKindFlag::METAL_SHARED_EVENT` in
525 /// `RenderSessionAttachOptions::producer_sync_kinds`, so that each frame
526 /// finishes before you acquire it. Release a frame with
527 /// `GpuSyncKind::CpuComplete` only once the reader has finished with its
528 /// surface.
529 ///
530 /// See `mln_map_attach_io_surface_ring` in the
531 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/apple_8h.html).
532 ///
533 /// # Errors
534 ///
535 /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
536 /// `RenderBackendFlag::METAL`.
537 /// - `Status::NativeError` when `context` names no device and the system
538 /// has no Metal device.
539 ///
540 /// # Safety
541 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
542 #[cfg(any(
543 target_os = "ios",
544 target_os = "macos",
545 target_os = "tvos",
546 target_os = "visionos"
547 ))]
548 pub unsafe fn attach_io_surface_ring(
549 &self,
550 descriptor: &IoSurfaceRingDescriptor,
551 options: &RenderSessionAttachOptions,
552 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
553 let mut call = self.inner.call();
554 let mut out_session = sys::mln_render_session(0);
555 let descriptor = call.reference(&descriptor)?;
556 let options = call.reference(&options)?;
557 let future = call.complete(
558 |map, completion, out_diagnostic| unsafe {
559 sys::mln_map_attach_io_surface_ring(
560 map,
561 descriptor,
562 options,
563 &mut out_session,
564 completion,
565 out_diagnostic,
566 )
567 },
568 completion::unit,
569 )?;
570 Ok((RenderSessionHandle::adopt(out_session)?, future))
571 }
572
573 /// Creates a session that renders the map into a ring of your Metal
574 /// textures.
575 ///
576 /// See `mln_map_attach_metal_borrowed_texture` in the
577 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
578 ///
579 /// # Errors
580 ///
581 /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
582 /// `RenderBackendFlag::METAL`, or when the target supports none of the
583 /// `producer_sync_kinds` in `options`.
584 ///
585 /// # Safety
586 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
587 #[cfg(any(
588 target_os = "ios",
589 target_os = "macos",
590 target_os = "tvos",
591 target_os = "visionos"
592 ))]
593 pub unsafe fn attach_metal_borrowed_texture(
594 &self,
595 descriptor: &MetalBorrowedTextureDescriptor,
596 options: &RenderSessionAttachOptions,
597 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
598 let mut call = self.inner.call();
599 let mut out_session = sys::mln_render_session(0);
600 let descriptor = call.reference(&descriptor)?;
601 let options = call.reference(&options)?;
602 let future = call.complete(
603 |map, completion, out_diagnostic| unsafe {
604 sys::mln_map_attach_metal_borrowed_texture(
605 map,
606 descriptor,
607 options,
608 &mut out_session,
609 completion,
610 out_diagnostic,
611 )
612 },
613 completion::unit,
614 )?;
615 Ok((RenderSessionHandle::adopt(out_session)?, future))
616 }
617
618 /// Creates a session that renders the map to a Metal layer.
619 ///
620 /// See `mln_map_attach_metal_surface` in the
621 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
622 ///
623 /// # Errors
624 ///
625 /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
626 /// `RenderBackendFlag::METAL`.
627 ///
628 /// # Safety
629 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
630 #[cfg(any(
631 target_os = "ios",
632 target_os = "macos",
633 target_os = "tvos",
634 target_os = "visionos"
635 ))]
636 pub unsafe fn attach_metal_surface(
637 &self,
638 descriptor: &MetalSurfaceDescriptor,
639 options: &RenderSessionAttachOptions,
640 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
641 let mut call = self.inner.call();
642 let mut out_session = sys::mln_render_session(0);
643 let descriptor = call.reference(&descriptor)?;
644 let options = call.reference(&options)?;
645 let future = call.complete(
646 |map, completion, out_diagnostic| unsafe {
647 sys::mln_map_attach_metal_surface(
648 map,
649 descriptor,
650 options,
651 &mut out_session,
652 completion,
653 out_diagnostic,
654 )
655 },
656 completion::unit,
657 )?;
658 Ok((RenderSessionHandle::adopt(out_session)?, future))
659 }
660
661 /// Attaches a render session that renders the map offscreen.
662 ///
663 /// Read each image's pixels with `RenderSessionHandle::read_texture()`.
664 ///
665 /// The session renders on `device`. When `device` is null, the session
666 /// creates a device with the default options, and releases it when the
667 /// session ends.
668 ///
669 /// See `mln_map_attach_offscreen` in the
670 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/offscreen_8h.html).
671 ///
672 /// # Errors
673 ///
674 /// - `Status::InvalidState` when the map already has a render session.
675 /// - `Status::NativeError` when `device` is null and the platform can't
676 /// create a device.
677 pub fn attach_offscreen(
678 &self,
679 descriptor: &OffscreenDescriptor,
680 options: &RenderSessionAttachOptions,
681 device: Option<&OffscreenDeviceHandle>,
682 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
683 let mut call = self.inner.call();
684 let device = device.map_or(sys::mln_offscreen_device(0), |device| device.inner.native());
685 let mut out_session = sys::mln_render_session(0);
686 let descriptor = call.reference(&descriptor)?;
687 let options = call.reference(&options)?;
688 let future = call.complete(
689 |map, completion, out_diagnostic| unsafe {
690 sys::mln_map_attach_offscreen(
691 map,
692 descriptor,
693 options,
694 device,
695 &mut out_session,
696 completion,
697 out_diagnostic,
698 )
699 },
700 completion::unit,
701 )?;
702 Ok((RenderSessionHandle::adopt(out_session)?, future))
703 }
704
705 /// Creates a session that presents the map to an OpenHarmony window, with a
706 /// graphics context that the library creates.
707 ///
708 /// A Vulkan build presents with `device`, or, when `device` is null, with a
709 /// device that the library creates. An OpenGL build uses an EGL context on
710 /// the default display, and `device` must be null. Attach with
711 /// `RenderDriverKind::CoreWorker`.
712 ///
713 /// When the platform destroys the window, such as in an `XComponent`'s
714 /// `onSurfaceDestroyed` callback, release the target with
715 /// `RenderSessionHandle::release_target()`, or give the session a new
716 /// window with `RenderSessionHandle::set_ohos_surface_target()`, without
717 /// waiting for that to complete. The session keeps its own reference to the
718 /// window and stays usable for the next window. A frame to the destroyed
719 /// window finishes with `RenderResult::TargetNotReady`, or with
720 /// `RenderResult::Rendered` if the window went away while the frame was
721 /// presenting.
722 ///
723 /// See `mln_map_attach_ohos_surface` in the
724 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/ohos_8h.html).
725 ///
726 /// # Errors
727 ///
728 /// - `Status::InvalidArgument` when no surface in this process has
729 /// `OhosSurfaceDescriptor::surface_id`, such as after the platform
730 /// destroyed it.
731 /// - `Status::Unsupported` when you created `device` without
732 /// `VulkanDeviceOptions::presentation`.
733 /// - `Status::Unsupported` when the GPU or the Vulkan loader can't present.
734 /// - `Status::NativeError` when the library can't create the graphics
735 /// context or the window's surface.
736 ///
737 /// # Safety
738 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
739 #[cfg(target_env = "ohos")]
740 pub unsafe fn attach_ohos_surface(
741 &self,
742 descriptor: &OhosSurfaceDescriptor,
743 device: Option<&VulkanDeviceHandle>,
744 options: &RenderSessionAttachOptions,
745 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
746 let mut call = self.inner.call();
747 let device = device.map_or(sys::mln_vulkan_device(0), |device| device.inner.native());
748 let mut out_session = sys::mln_render_session(0);
749 let descriptor = call.reference(&descriptor)?;
750 let options = call.reference(&options)?;
751 let future = call.complete(
752 |map, completion, out_diagnostic| unsafe {
753 sys::mln_map_attach_ohos_surface(
754 map,
755 descriptor,
756 device,
757 options,
758 &mut out_session,
759 completion,
760 out_diagnostic,
761 )
762 },
763 completion::unit,
764 )?;
765 Ok((RenderSessionHandle::adopt(out_session)?, future))
766 }
767
768 /// Creates a session that renders the map into a ring of your OpenGL
769 /// textures.
770 ///
771 /// See `mln_map_attach_open_gl_borrowed_texture` in the
772 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
773 ///
774 /// # Errors
775 ///
776 /// - `Status::Unsupported` when `open_gl_supported_context_provider_mask()`
777 /// lacks the context's platform, or when the target supports none of the
778 /// `producer_sync_kinds` in `options`.
779 ///
780 /// # Safety
781 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
782 pub unsafe fn attach_open_gl_borrowed_texture(
783 &self,
784 descriptor: &OpenGlBorrowedTextureDescriptor<'_>,
785 options: &RenderSessionAttachOptions,
786 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
787 let mut call = self.inner.call();
788 let mut out_session = sys::mln_render_session(0);
789 let descriptor = call.reference(&descriptor)?;
790 let options = call.reference(&options)?;
791 let future = call.complete(
792 |map, completion, out_diagnostic| unsafe {
793 sys::mln_map_attach_open_gl_borrowed_texture(
794 map,
795 descriptor,
796 options,
797 &mut out_session,
798 completion,
799 out_diagnostic,
800 )
801 },
802 completion::unit,
803 )?;
804 Ok((RenderSessionHandle::adopt(out_session)?, future))
805 }
806
807 /// Creates a session that renders the map to an OpenGL surface.
808 ///
809 /// See `mln_map_attach_open_gl_surface` in the
810 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
811 ///
812 /// # Errors
813 ///
814 /// - `Status::Unsupported` when `open_gl_supported_context_provider_mask()`
815 /// lacks the context's platform.
816 ///
817 /// # Safety
818 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
819 pub unsafe fn attach_open_gl_surface(
820 &self,
821 descriptor: &OpenGlSurfaceDescriptor<'_>,
822 options: &RenderSessionAttachOptions,
823 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
824 let mut call = self.inner.call();
825 let mut out_session = sys::mln_render_session(0);
826 let descriptor = call.reference(&descriptor)?;
827 let options = call.reference(&options)?;
828 let future = call.complete(
829 |map, completion, out_diagnostic| unsafe {
830 sys::mln_map_attach_open_gl_surface(
831 map,
832 descriptor,
833 options,
834 &mut out_session,
835 completion,
836 out_diagnostic,
837 )
838 },
839 completion::unit,
840 )?;
841 Ok((RenderSessionHandle::adopt(out_session)?, future))
842 }
843
844 /// Creates a session that renders the map into a ring of your Vulkan
845 /// images.
846 ///
847 /// See `mln_map_attach_vulkan_borrowed_texture` in the
848 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
849 ///
850 /// # Errors
851 ///
852 /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
853 /// `RenderBackendFlag::VULKAN`, or when the target supports none of the
854 /// `producer_sync_kinds` in `options`.
855 ///
856 /// # Safety
857 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
858 #[cfg(any(
859 target_os = "android",
860 target_os = "freebsd",
861 target_os = "linux",
862 target_os = "macos",
863 target_os = "windows"
864 ))]
865 pub unsafe fn attach_vulkan_borrowed_texture(
866 &self,
867 descriptor: &VulkanBorrowedTextureDescriptor,
868 options: &RenderSessionAttachOptions,
869 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
870 let mut call = self.inner.call();
871 let mut out_session = sys::mln_render_session(0);
872 let descriptor = call.reference(&descriptor)?;
873 let options = call.reference(&options)?;
874 let future = call.complete(
875 |map, completion, out_diagnostic| unsafe {
876 sys::mln_map_attach_vulkan_borrowed_texture(
877 map,
878 descriptor,
879 options,
880 &mut out_session,
881 completion,
882 out_diagnostic,
883 )
884 },
885 completion::unit,
886 )?;
887 Ok((RenderSessionHandle::adopt(out_session)?, future))
888 }
889
890 /// Creates a session that renders the map to a Vulkan surface.
891 ///
892 /// See `mln_map_attach_vulkan_surface` in the
893 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
894 ///
895 /// # Errors
896 ///
897 /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
898 /// `RenderBackendFlag::VULKAN`.
899 ///
900 /// # Safety
901 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
902 #[cfg(any(
903 target_os = "android",
904 target_os = "freebsd",
905 target_os = "linux",
906 target_os = "macos",
907 target_os = "windows"
908 ))]
909 pub unsafe fn attach_vulkan_surface(
910 &self,
911 descriptor: &VulkanSurfaceDescriptor,
912 options: &RenderSessionAttachOptions,
913 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
914 let mut call = self.inner.call();
915 let mut out_session = sys::mln_render_session(0);
916 let descriptor = call.reference(&descriptor)?;
917 let options = call.reference(&options)?;
918 let future = call.complete(
919 |map, completion, out_diagnostic| unsafe {
920 sys::mln_map_attach_vulkan_surface(
921 map,
922 descriptor,
923 options,
924 &mut out_session,
925 completion,
926 out_diagnostic,
927 )
928 },
929 completion::unit,
930 )?;
931 Ok((RenderSessionHandle::adopt(out_session)?, future))
932 }
933
934 /// Creates a session that presents the map to a Wayland surface, with a
935 /// graphics context that the library creates.
936 ///
937 /// A Vulkan build presents with `device`, or, when `device` is null, with a
938 /// device that the library creates. An OpenGL build uses an EGL context on
939 /// the display, and `device` must be null. Attach with
940 /// `RenderDriverKind::CoreWorker`.
941 ///
942 /// The session presents without waiting for the compositor, so demand at
943 /// most one frame per display refresh.
944 ///
945 /// Keep the surface until a release or replacement of the target, or a
946 /// detach of the session, completes. Keep the display connected until the
947 /// session's detach completes. In an OpenGL build, if you also use EGL on
948 /// the display, initialize it before you attach.
949 ///
950 /// See `mln_map_attach_wayland_surface` in the
951 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/wayland_8h.html).
952 ///
953 /// # Errors
954 ///
955 /// - `Status::Unsupported` when you created `device` without
956 /// `VulkanDeviceOptions::presentation`.
957 /// - `Status::Unsupported` when the GPU or the Vulkan loader can't present
958 /// to Wayland.
959 /// - `Status::NativeError` when the library can't create the graphics
960 /// context or present to the surface.
961 ///
962 /// # Safety
963 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
964 #[cfg(any(
965 target_os = "freebsd",
966 all(target_os = "linux", not(target_env = "ohos"))
967 ))]
968 pub unsafe fn attach_wayland_surface(
969 &self,
970 descriptor: &WaylandSurfaceDescriptor,
971 device: Option<&VulkanDeviceHandle>,
972 options: &RenderSessionAttachOptions,
973 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
974 let mut call = self.inner.call();
975 let device = device.map_or(sys::mln_vulkan_device(0), |device| device.inner.native());
976 let mut out_session = sys::mln_render_session(0);
977 let descriptor = call.reference(&descriptor)?;
978 let options = call.reference(&options)?;
979 let future = call.complete(
980 |map, completion, out_diagnostic| unsafe {
981 sys::mln_map_attach_wayland_surface(
982 map,
983 descriptor,
984 device,
985 options,
986 &mut out_session,
987 completion,
988 out_diagnostic,
989 )
990 },
991 completion::unit,
992 )?;
993 Ok((RenderSessionHandle::adopt(out_session)?, future))
994 }
995
996 /// Creates a session that renders the map into a ring of your WebGPU
997 /// textures.
998 ///
999 /// See `mln_map_attach_web_gpu_borrowed_texture` in the
1000 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
1001 ///
1002 /// # Errors
1003 ///
1004 /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
1005 /// `RenderBackendFlag::WEB_GPU`, or when the target supports none of the
1006 /// `producer_sync_kinds` in `options`.
1007 ///
1008 /// # Safety
1009 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
1010 #[cfg(target_os = "emscripten")]
1011 pub unsafe fn attach_web_gpu_borrowed_texture(
1012 &self,
1013 descriptor: &WebGpuBorrowedTextureDescriptor,
1014 options: &RenderSessionAttachOptions,
1015 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
1016 let mut call = self.inner.call();
1017 let mut out_session = sys::mln_render_session(0);
1018 let descriptor = call.reference(&descriptor)?;
1019 let options = call.reference(&options)?;
1020 let future = call.complete(
1021 |map, completion, out_diagnostic| unsafe {
1022 sys::mln_map_attach_web_gpu_borrowed_texture(
1023 map,
1024 descriptor,
1025 options,
1026 &mut out_session,
1027 completion,
1028 out_diagnostic,
1029 )
1030 },
1031 completion::unit,
1032 )?;
1033 Ok((RenderSessionHandle::adopt(out_session)?, future))
1034 }
1035
1036 /// Creates a session that renders the map to a WebGPU surface.
1037 ///
1038 /// See `mln_map_attach_web_gpu_surface` in the
1039 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
1040 ///
1041 /// # Errors
1042 ///
1043 /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
1044 /// `RenderBackendFlag::WEB_GPU`.
1045 ///
1046 /// # Safety
1047 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
1048 #[cfg(target_os = "emscripten")]
1049 pub unsafe fn attach_web_gpu_surface(
1050 &self,
1051 descriptor: &WebGpuSurfaceDescriptor,
1052 options: &RenderSessionAttachOptions,
1053 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
1054 let mut call = self.inner.call();
1055 let mut out_session = sys::mln_render_session(0);
1056 let descriptor = call.reference(&descriptor)?;
1057 let options = call.reference(&options)?;
1058 let future = call.complete(
1059 |map, completion, out_diagnostic| unsafe {
1060 sys::mln_map_attach_web_gpu_surface(
1061 map,
1062 descriptor,
1063 options,
1064 &mut out_session,
1065 completion,
1066 out_diagnostic,
1067 )
1068 },
1069 completion::unit,
1070 )?;
1071 Ok((RenderSessionHandle::adopt(out_session)?, future))
1072 }
1073
1074 /// Creates a session that presents the map to a Win32 window, with a
1075 /// graphics context that the library creates.
1076 ///
1077 /// A Vulkan build presents with `device`, or, when `device` is null, with a
1078 /// device that the library creates. An OpenGL build uses a WGL context, and
1079 /// `device` must be null. Attach with `RenderDriverKind::CoreWorker`.
1080 ///
1081 /// An OpenGL build sets the window's pixel format, so don't set one
1082 /// yourself.
1083 ///
1084 /// The session presents without waiting for the display, so demand at most
1085 /// one frame per display refresh. While the window is minimized, frame
1086 /// demands finish with `RenderResult::TargetNotReady`.
1087 ///
1088 /// Keep the window until a release or replacement of the target, or a
1089 /// detach of the session, completes.
1090 ///
1091 /// See `mln_map_attach_win32_window` in the
1092 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/win32_8h.html).
1093 ///
1094 /// # Errors
1095 ///
1096 /// - `Status::InvalidArgument` when `window` isn't a window, or, in an
1097 /// OpenGL build, already has another pixel format.
1098 /// - `Status::InvalidState` when `window` is minimized or has no client
1099 /// area.
1100 /// - `Status::Unsupported` when you created `device` without
1101 /// `VulkanDeviceOptions::presentation`.
1102 /// - `Status::InvalidState` when `window` was minimized before the attach
1103 /// ran.
1104 /// - `Status::Unsupported` when the GPU or the Vulkan loader can't present.
1105 /// - `Status::NativeError` when the library can't create the graphics
1106 /// context or present to the window.
1107 ///
1108 /// # Safety
1109 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
1110 #[cfg(target_os = "windows")]
1111 pub unsafe fn attach_win32_window(
1112 &self,
1113 descriptor: &Win32WindowDescriptor,
1114 device: Option<&VulkanDeviceHandle>,
1115 options: &RenderSessionAttachOptions,
1116 ) -> Result<(RenderSessionHandle, NativeFuture<()>)> {
1117 let mut call = self.inner.call();
1118 let device = device.map_or(sys::mln_vulkan_device(0), |device| device.inner.native());
1119 let mut out_session = sys::mln_render_session(0);
1120 let descriptor = call.reference(&descriptor)?;
1121 let options = call.reference(&options)?;
1122 let future = call.complete(
1123 |map, completion, out_diagnostic| unsafe {
1124 sys::mln_map_attach_win32_window(
1125 map,
1126 descriptor,
1127 device,
1128 options,
1129 &mut out_session,
1130 completion,
1131 out_diagnostic,
1132 )
1133 },
1134 completion::unit,
1135 )?;
1136 Ok((RenderSessionHandle::adopt(out_session)?, future))
1137 }
1138
1139 /// Holds back the map's changes from rendering until
1140 /// `MapHandle::end_command_group()`, so they show in the same frame.
1141 ///
1142 /// Groups nest, and the changes render when the outermost group ends.
1143 ///
1144 /// See `mln_map_begin_command_group` in the
1145 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1146 pub fn begin_command_group(&self) -> Result<NativeFuture<CommandCompletion>> {
1147 let call = self.inner.call();
1148 call.command(|map, completion, out_diagnostic| unsafe {
1149 sys::mln_map_begin_command_group(map, completion, out_diagnostic)
1150 })
1151 }
1152
1153 /// Computes a camera that fits a GeoJSON geometry in the map's view.
1154 ///
1155 /// `geometry` is a GeoJSON geometry object with at least one coordinate,
1156 /// not a feature. The camera keeps the map's bearing and pitch unless
1157 /// `fit_options` sets them, and its zoom stays within the map's zoom
1158 /// limits.
1159 ///
1160 /// See `mln_map_camera_for_geometry` in the
1161 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1162 ///
1163 /// # Errors
1164 ///
1165 /// - `Status::InvalidArgument` when the padding in `fit_options` leaves no
1166 /// room for the area.
1167 pub fn camera_for_geometry(
1168 &self,
1169 geometry: &str,
1170 fit_options: Option<&CameraFitOptions>,
1171 ) -> Result<NativeFuture<CameraOptions>> {
1172 let mut call = self.inner.call();
1173 let geometry = call.input(&geometry)?;
1174 let fit_options = call.optional_reference(fit_options.as_ref())?;
1175 call.complete(
1176 |map, completion, out_diagnostic| unsafe {
1177 sys::mln_map_camera_for_geometry(
1178 map,
1179 geometry,
1180 fit_options,
1181 completion,
1182 out_diagnostic,
1183 )
1184 },
1185 completion::value::<sys::mln_camera_options, _>,
1186 )
1187 }
1188
1189 /// Computes a camera that fits `bounds` in the map's view.
1190 ///
1191 /// The camera keeps the map's bearing and pitch unless `fit_options` sets
1192 /// them, and its zoom stays within the map's zoom limits.
1193 ///
1194 /// See `mln_map_camera_for_lat_lng_bounds` in the
1195 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1196 ///
1197 /// # Errors
1198 ///
1199 /// - `Status::InvalidArgument` when the padding in `fit_options` leaves no
1200 /// room for the area.
1201 pub fn camera_for_lat_lng_bounds(
1202 &self,
1203 bounds: LatLngBounds,
1204 fit_options: Option<&CameraFitOptions>,
1205 ) -> Result<NativeFuture<CameraOptions>> {
1206 let mut call = self.inner.call();
1207 let bounds = call.input(&bounds)?;
1208 let fit_options = call.optional_reference(fit_options.as_ref())?;
1209 call.complete(
1210 |map, completion, out_diagnostic| unsafe {
1211 sys::mln_map_camera_for_lat_lng_bounds(
1212 map,
1213 bounds,
1214 fit_options,
1215 completion,
1216 out_diagnostic,
1217 )
1218 },
1219 completion::value::<sys::mln_camera_options, _>,
1220 )
1221 }
1222
1223 /// Computes a camera that fits `coordinates` in the map's view.
1224 ///
1225 /// `coordinates` must not be empty. The camera keeps the map's bearing and
1226 /// pitch unless `fit_options` sets them, and its zoom stays within the
1227 /// map's zoom limits.
1228 ///
1229 /// See `mln_map_camera_for_lat_lngs` in the
1230 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1231 ///
1232 /// # Errors
1233 ///
1234 /// - `Status::InvalidArgument` when the padding in `fit_options` leaves no
1235 /// room for the area.
1236 pub fn camera_for_lat_lngs(
1237 &self,
1238 coordinates: &[LatLng],
1239 fit_options: Option<&CameraFitOptions>,
1240 ) -> Result<NativeFuture<CameraOptions>> {
1241 let mut call = self.inner.call();
1242 let coordinate_count = convert::count(coordinates.len())?;
1243 let coordinates = call.array(coordinates)?;
1244 let fit_options = call.optional_reference(fit_options.as_ref())?;
1245 call.complete(
1246 |map, completion, out_diagnostic| unsafe {
1247 sys::mln_map_camera_for_lat_lngs(
1248 map,
1249 coordinates,
1250 coordinate_count,
1251 fit_options,
1252 completion,
1253 out_diagnostic,
1254 )
1255 },
1256 completion::value::<sys::mln_camera_options, _>,
1257 )
1258 }
1259
1260 /// Stops every running camera animation where it is.
1261 ///
1262 /// The end handler of each stopped animation reports
1263 /// `CameraTransitionOutcome::Cancelled`.
1264 ///
1265 /// See `mln_map_cancel_camera_transitions` in the
1266 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1267 pub fn cancel_camera_transitions(&self) -> Result<NativeFuture<CommandCompletion>> {
1268 let call = self.inner.call();
1269 call.command(|map, completion, out_diagnostic| unsafe {
1270 sys::mln_map_cancel_camera_transitions(map, completion, out_diagnostic)
1271 })
1272 }
1273
1274 /// Stops the running camera animations whose animation options set
1275 /// `transition_id`.
1276 ///
1277 /// Other animations keep running. The end handler of each stopped animation
1278 /// reports `CameraTransitionOutcome::Cancelled`.
1279 ///
1280 /// See `mln_map_cancel_camera_transitions_with_id` in the
1281 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1282 pub fn cancel_camera_transitions_with_id(
1283 &self,
1284 transition_id: u64,
1285 ) -> Result<NativeFuture<CommandCompletion>> {
1286 let call = self.inner.call();
1287 call.command(|map, completion, out_diagnostic| unsafe {
1288 sys::mln_map_cancel_camera_transitions_with_id(
1289 map,
1290 transition_id,
1291 completion,
1292 out_diagnostic,
1293 )
1294 })
1295 }
1296
1297 /// Releases the map in any state, and finishes in the background.
1298 ///
1299 /// Use it from destructors and finalizers. Otherwise, use
1300 /// `MapHandle::release()`.
1301 ///
1302 /// See `mln_map_dispose` in the
1303 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1304 pub fn dispose(self) -> std::result::Result<(), ReleaseError<Self>> {
1305 self.consume(|map| {
1306 let mut call = Call::new(map);
1307 call.status(|map, out_diagnostic| unsafe { sys::mln_map_dispose(map, out_diagnostic) })
1308 })
1309 }
1310
1311 /// Logs debugging information about the map's style and sources.
1312 ///
1313 /// See `mln_map_dump_debug_logs` in the
1314 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1315 pub fn dump_debug_logs(&self) -> Result<NativeFuture<CommandCompletion>> {
1316 let call = self.inner.call();
1317 call.command(|map, completion, out_diagnostic| unsafe {
1318 sys::mln_map_dump_debug_logs(map, completion, out_diagnostic)
1319 })
1320 }
1321
1322 /// Ends the group that `MapHandle::begin_command_group()` began.
1323 ///
1324 /// See `mln_map_end_command_group` in the
1325 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1326 pub fn end_command_group(&self) -> Result<NativeFuture<CommandCompletion>> {
1327 let call = self.inner.call();
1328 call.command(|map, completion, out_diagnostic| unsafe {
1329 sys::mln_map_end_command_group(map, completion, out_diagnostic)
1330 })
1331 }
1332
1333 /// Moves the camera to fit a GeoJSON geometry in the map's view, at once or
1334 /// with an animation.
1335 ///
1336 /// `geometry` is a GeoJSON geometry object with at least one coordinate,
1337 /// not a feature. The camera is the one that
1338 /// `MapHandle::camera_for_geometry()` computes after the commands sent
1339 /// before this one apply. The function finishes when the map applies the
1340 /// change, before an animation ends.
1341 ///
1342 /// See `mln_map_fit_camera_to_geometry` in the
1343 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1344 ///
1345 /// # Errors
1346 ///
1347 /// - `Status::InvalidArgument` when the padding in `update` leaves no room
1348 /// for the area. The camera doesn't move.
1349 pub fn fit_camera_to_geometry(
1350 &self,
1351 geometry: &str,
1352 update: &CameraFitUpdate,
1353 ) -> Result<NativeFuture<CommandCompletion>> {
1354 let mut call = self.inner.call();
1355 let geometry = call.input(&geometry)?;
1356 let update = call.reference(&update)?;
1357 call.command(|map, completion, out_diagnostic| unsafe {
1358 sys::mln_map_fit_camera_to_geometry(map, geometry, update, completion, out_diagnostic)
1359 })
1360 }
1361
1362 /// Moves the camera to fit `bounds` in the map's view, at once or with an
1363 /// animation.
1364 ///
1365 /// The camera is the one that `MapHandle::camera_for_lat_lng_bounds()`
1366 /// computes after the commands sent before this one apply. The function
1367 /// finishes when the map applies the change, before an animation ends.
1368 ///
1369 /// See `mln_map_fit_camera_to_lat_lng_bounds` in the
1370 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1371 ///
1372 /// # Errors
1373 ///
1374 /// - `Status::InvalidArgument` when the padding in `update` leaves no room
1375 /// for the area. The camera doesn't move.
1376 pub fn fit_camera_to_lat_lng_bounds(
1377 &self,
1378 bounds: LatLngBounds,
1379 update: &CameraFitUpdate,
1380 ) -> Result<NativeFuture<CommandCompletion>> {
1381 let mut call = self.inner.call();
1382 let bounds = call.input(&bounds)?;
1383 let update = call.reference(&update)?;
1384 call.command(|map, completion, out_diagnostic| unsafe {
1385 sys::mln_map_fit_camera_to_lat_lng_bounds(
1386 map,
1387 bounds,
1388 update,
1389 completion,
1390 out_diagnostic,
1391 )
1392 })
1393 }
1394
1395 /// Moves the camera to fit `coordinates` in the map's view, at once or with
1396 /// an animation.
1397 ///
1398 /// `coordinates` must not be empty. The camera is the one that
1399 /// `MapHandle::camera_for_lat_lngs()` computes after the commands sent
1400 /// before this one apply. The function finishes when the map applies the
1401 /// change, before an animation ends.
1402 ///
1403 /// See `mln_map_fit_camera_to_lat_lngs` in the
1404 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1405 ///
1406 /// # Errors
1407 ///
1408 /// - `Status::InvalidArgument` when the padding in `update` leaves no room
1409 /// for the area. The camera doesn't move.
1410 pub fn fit_camera_to_lat_lngs(
1411 &self,
1412 coordinates: &[LatLng],
1413 update: &CameraFitUpdate,
1414 ) -> Result<NativeFuture<CommandCompletion>> {
1415 let mut call = self.inner.call();
1416 let coordinate_count = convert::count(coordinates.len())?;
1417 let coordinates = call.array(coordinates)?;
1418 let update = call.reference(&update)?;
1419 call.command(|map, completion, out_diagnostic| unsafe {
1420 sys::mln_map_fit_camera_to_lat_lngs(
1421 map,
1422 coordinates,
1423 coordinate_count,
1424 update,
1425 completion,
1426 out_diagnostic,
1427 )
1428 })
1429 }
1430
1431 /// Reads the map's camera.
1432 ///
1433 /// The query reads the camera after the map applies the commands sent
1434 /// before it.
1435 ///
1436 /// See `mln_map_get_camera` in the
1437 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1438 pub fn get_camera(&self) -> Result<NativeFuture<CameraQueryResult>> {
1439 let call = self.inner.call();
1440 call.complete(
1441 |map, completion, out_diagnostic| unsafe {
1442 sys::mln_map_get_camera(map, completion, out_diagnostic)
1443 },
1444 completion::value::<sys::mln_camera_query_result, _>,
1445 )
1446 }
1447
1448 /// Reads the state of a feature, as a JSON object.
1449 ///
1450 /// The object is empty when the feature has no state.
1451 ///
1452 /// See `mln_map_get_feature_state` in the
1453 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1454 pub fn get_feature_state(
1455 &self,
1456 selector: &FeatureStateSelector<'_>,
1457 ) -> Result<NativeFuture<String>> {
1458 let mut call = self.inner.call();
1459 let selector = call.reference(&selector)?;
1460 call.complete(
1461 |map, completion, out_diagnostic| unsafe {
1462 sys::mln_map_get_feature_state(map, selector, completion, out_diagnostic)
1463 },
1464 completion::value::<sys::mln_buffer_view, _>,
1465 )
1466 }
1467
1468 /// Reads the global state of the map's style as a JSON object.
1469 ///
1470 /// See `mln_map_get_global_state` in the
1471 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1472 pub fn get_global_state(&self) -> Result<NativeFuture<String>> {
1473 let call = self.inner.call();
1474 call.complete(
1475 |map, completion, out_diagnostic| unsafe {
1476 sys::mln_map_get_global_state(map, completion, out_diagnostic)
1477 },
1478 completion::value::<sys::mln_buffer_view, _>,
1479 )
1480 }
1481
1482 /// Reads the corners of an image source's image, clockwise from the top
1483 /// left.
1484 ///
1485 /// See `mln_map_get_image_source_coordinates` in the
1486 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1487 ///
1488 /// # Errors
1489 ///
1490 /// - `Status::NotFound` when the style has no source named `source_id`.
1491 /// - `Status::InvalidArgument` when the source named `source_id` isn't an
1492 /// image source.
1493 pub fn get_image_source_coordinates(
1494 &self,
1495 source_id: &str,
1496 ) -> Result<NativeFuture<Vec<LatLng>>> {
1497 let mut call = self.inner.call();
1498 let source_id = call.input(&source_id)?;
1499 call.complete(
1500 |map, completion, out_diagnostic| unsafe {
1501 sys::mln_map_get_image_source_coordinates(
1502 map,
1503 source_id,
1504 completion,
1505 out_diagnostic,
1506 )
1507 },
1508 completion::list::<sys::mln_lat_lng, _>,
1509 )
1510 }
1511
1512 /// Reads the JSON of the style that the map loaded.
1513 ///
1514 /// The JSON doesn't include the changes made to the style since it loaded.
1515 ///
1516 /// See `mln_map_get_loaded_style_json` in the
1517 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1518 pub fn get_loaded_style_json(&self) -> Result<NativeFuture<String>> {
1519 let call = self.inner.call();
1520 call.complete(
1521 |map, completion, out_diagnostic| unsafe {
1522 sys::mln_map_get_loaded_style_json(map, completion, out_diagnostic)
1523 },
1524 completion::value::<sys::mln_buffer_view, _>,
1525 )
1526 }
1527
1528 /// Copies the map's state.
1529 ///
1530 /// The copy doesn't wait for pending commands. To read the camera after
1531 /// they apply, use `MapHandle::get_camera()`.
1532 ///
1533 /// See `mln_map_get_snapshot` in the
1534 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1535 ///
1536 /// # Errors
1537 ///
1538 /// - `Status::InvalidState` until `RuntimeHandle::create_map()` completes
1539 /// with `Status::Ok`.
1540 pub fn get_snapshot(&self) -> Result<MapSnapshot> {
1541 let mut call = self.inner.call();
1542 let mut out_snapshot: sys::mln_map_snapshot = unsafe { std::mem::zeroed() };
1543 out_snapshot.size = std::mem::size_of::<sys::mln_map_snapshot>() as _;
1544 call.status(|map, out_diagnostic| unsafe {
1545 sys::mln_map_get_snapshot(map, &mut out_snapshot, out_diagnostic)
1546 })?;
1547 Ok(unsafe { from_native(out_snapshot) }?)
1548 }
1549
1550 /// Reads an image of the map's style.
1551 ///
1552 /// Completes with no value when the style has no image named `image_id`.
1553 ///
1554 /// See `mln_map_get_style_image` in the
1555 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1556 pub fn get_style_image(&self, image_id: &str) -> Result<NativeFuture<Option<StyleImageInfo>>> {
1557 let mut call = self.inner.call();
1558 let image_id = call.input(&image_id)?;
1559 call.complete(
1560 |map, completion, out_diagnostic| unsafe {
1561 sys::mln_map_get_style_image(map, image_id, completion, out_diagnostic)
1562 },
1563 completion::optional::<sys::mln_style_image_info, _>,
1564 )
1565 }
1566
1567 /// Reads a layer of the map's style.
1568 ///
1569 /// Completes with no value when the style has no layer named `layer_id`.
1570 ///
1571 /// See `mln_map_get_style_layer` in the
1572 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1573 pub fn get_style_layer(&self, layer_id: &str) -> Result<NativeFuture<Option<StyleLayerInfo>>> {
1574 let mut call = self.inner.call();
1575 let layer_id = call.input(&layer_id)?;
1576 call.complete(
1577 |map, completion, out_diagnostic| unsafe {
1578 sys::mln_map_get_style_layer(map, layer_id, completion, out_diagnostic)
1579 },
1580 completion::optional::<sys::mln_style_layer_info, _>,
1581 )
1582 }
1583
1584 /// Reads a layer of the map's style as a
1585 /// \[layer\](https://maplibre.org/maplibre-style-spec/layers/) object.
1586 ///
1587 /// Completes with no value when the style has no layer named `layer_id`.
1588 ///
1589 /// See `mln_map_get_style_layer_json` in the
1590 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1591 pub fn get_style_layer_json(&self, layer_id: &str) -> Result<NativeFuture<Option<String>>> {
1592 let mut call = self.inner.call();
1593 let layer_id = call.input(&layer_id)?;
1594 call.complete(
1595 |map, completion, out_diagnostic| unsafe {
1596 sys::mln_map_get_style_layer_json(map, layer_id, completion, out_diagnostic)
1597 },
1598 completion::optional::<sys::mln_buffer_view, _>,
1599 )
1600 }
1601
1602 /// Reads a property of a layer in the map's style.
1603 ///
1604 /// The value can differ in form from the value that was set: a color set as
1605 /// `"#ff0000"` reads back as `["rgba", 255, 0, 0, 1]`.
1606 ///
1607 /// Completes with no value when the layer doesn't set the property.
1608 ///
1609 /// See `mln_map_get_style_layer_property` in the
1610 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1611 ///
1612 /// # Errors
1613 ///
1614 /// - `Status::NotFound` when the style has no layer named `layer_id`.
1615 pub fn get_style_layer_property(
1616 &self,
1617 layer_id: &str,
1618 property_name: &str,
1619 ) -> Result<NativeFuture<Option<String>>> {
1620 let mut call = self.inner.call();
1621 let layer_id = call.input(&layer_id)?;
1622 let property_name = call.input(&property_name)?;
1623 call.complete(
1624 |map, completion, out_diagnostic| unsafe {
1625 sys::mln_map_get_style_layer_property(
1626 map,
1627 layer_id,
1628 property_name,
1629 completion,
1630 out_diagnostic,
1631 )
1632 },
1633 completion::optional::<sys::mln_buffer_view, _>,
1634 )
1635 }
1636
1637 /// Reads a property of the light of the map's style.
1638 ///
1639 /// The value can differ in form from the value that was set: a color set as
1640 /// `"#ff0000"` reads back as `["rgba", 255, 0, 0, 1]`.
1641 ///
1642 /// Completes with no value when the light doesn't set the property.
1643 ///
1644 /// See `mln_map_get_style_light_property` in the
1645 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1646 pub fn get_style_light_property(
1647 &self,
1648 property_name: &str,
1649 ) -> Result<NativeFuture<Option<String>>> {
1650 let mut call = self.inner.call();
1651 let property_name = call.input(&property_name)?;
1652 call.complete(
1653 |map, completion, out_diagnostic| unsafe {
1654 sys::mln_map_get_style_light_property(
1655 map,
1656 property_name,
1657 completion,
1658 out_diagnostic,
1659 )
1660 },
1661 completion::optional::<sys::mln_buffer_view, _>,
1662 )
1663 }
1664
1665 /// Reads a source of the map's style.
1666 ///
1667 /// A tile source with a `url` has an empty attribution until its TileJSON
1668 /// loads, which raises `RuntimeEventType::MapSourceChanged`.
1669 ///
1670 /// Completes with no value when the style has no source named `source_id`.
1671 ///
1672 /// See `mln_map_get_style_source` in the
1673 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1674 pub fn get_style_source(
1675 &self,
1676 source_id: &str,
1677 ) -> Result<NativeFuture<Option<StyleSourceInfo>>> {
1678 let mut call = self.inner.call();
1679 let source_id = call.input(&source_id)?;
1680 call.complete(
1681 |map, completion, out_diagnostic| unsafe {
1682 sys::mln_map_get_style_source(map, source_id, completion, out_diagnostic)
1683 },
1684 completion::optional::<sys::mln_style_source_info, _>,
1685 )
1686 }
1687
1688 /// Reads the default transition of the map's style.
1689 ///
1690 /// See `mln_map_get_style_transition_options` in the
1691 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1692 pub fn get_style_transition_options(&self) -> Result<NativeFuture<StyleTransitionOptions>> {
1693 let call = self.inner.call();
1694 call.complete(
1695 |map, completion, out_diagnostic| unsafe {
1696 sys::mln_map_get_style_transition_options(map, completion, out_diagnostic)
1697 },
1698 completion::value::<sys::mln_style_transition_options, _>,
1699 )
1700 }
1701
1702 /// Reads the URL of the map's style.
1703 ///
1704 /// The URL is empty when the style came from `MapHandle::set_style_json()`.
1705 ///
1706 /// See `mln_map_get_style_url` in the
1707 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1708 pub fn get_style_url(&self) -> Result<NativeFuture<String>> {
1709 let call = self.inner.call();
1710 call.complete(
1711 |map, completion, out_diagnostic| unsafe {
1712 sys::mln_map_get_style_url(map, completion, out_diagnostic)
1713 },
1714 completion::value::<sys::mln_buffer_view, _>,
1715 )
1716 }
1717
1718 /// Makes a custom geometry source ask again for the tiles in `bounds` that
1719 /// the map still needs.
1720 ///
1721 /// See `mln_map_invalidate_custom_geometry_source_region` in the
1722 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1723 ///
1724 /// # Errors
1725 ///
1726 /// - `Status::NotFound` when the style has no source named `source_id`.
1727 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
1728 /// custom geometry source.
1729 pub fn invalidate_custom_geometry_source_region(
1730 &self,
1731 source_id: &str,
1732 bounds: LatLngBounds,
1733 ) -> Result<NativeFuture<CommandCompletion>> {
1734 let mut call = self.inner.call();
1735 let source_id = call.input(&source_id)?;
1736 let bounds = call.input(&bounds)?;
1737 call.command(|map, completion, out_diagnostic| unsafe {
1738 sys::mln_map_invalidate_custom_geometry_source_region(
1739 map,
1740 source_id,
1741 bounds,
1742 completion,
1743 out_diagnostic,
1744 )
1745 })
1746 }
1747
1748 /// Makes a custom geometry source ask for a tile again when the map needs
1749 /// it.
1750 ///
1751 /// See `mln_map_invalidate_custom_geometry_source_tile` in the
1752 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1753 ///
1754 /// # Errors
1755 ///
1756 /// - `Status::NotFound` when the style has no source named `source_id`.
1757 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
1758 /// custom geometry source.
1759 pub fn invalidate_custom_geometry_source_tile(
1760 &self,
1761 source_id: &str,
1762 tile_id: CanonicalTileId,
1763 ) -> Result<NativeFuture<CommandCompletion>> {
1764 let mut call = self.inner.call();
1765 let source_id = call.input(&source_id)?;
1766 let tile_id = call.input(&tile_id)?;
1767 call.command(|map, completion, out_diagnostic| unsafe {
1768 sys::mln_map_invalidate_custom_geometry_source_tile(
1769 map,
1770 source_id,
1771 tile_id,
1772 completion,
1773 out_diagnostic,
1774 )
1775 })
1776 }
1777
1778 /// Makes a custom vector source ask again for the tiles in `bounds` that
1779 /// the map still needs.
1780 ///
1781 /// See `mln_map_invalidate_custom_vector_source_region` in the
1782 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1783 ///
1784 /// # Errors
1785 ///
1786 /// - `Status::NotFound` when the style has no source named `source_id`.
1787 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
1788 /// custom vector source.
1789 pub fn invalidate_custom_vector_source_region(
1790 &self,
1791 source_id: &str,
1792 bounds: LatLngBounds,
1793 ) -> Result<NativeFuture<CommandCompletion>> {
1794 let mut call = self.inner.call();
1795 let source_id = call.input(&source_id)?;
1796 let bounds = call.input(&bounds)?;
1797 call.command(|map, completion, out_diagnostic| unsafe {
1798 sys::mln_map_invalidate_custom_vector_source_region(
1799 map,
1800 source_id,
1801 bounds,
1802 completion,
1803 out_diagnostic,
1804 )
1805 })
1806 }
1807
1808 /// Makes a custom vector source ask for a tile again when the map needs it.
1809 ///
1810 /// See `mln_map_invalidate_custom_vector_source_tile` in the
1811 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1812 ///
1813 /// # Errors
1814 ///
1815 /// - `Status::NotFound` when the style has no source named `source_id`.
1816 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
1817 /// custom vector source.
1818 pub fn invalidate_custom_vector_source_tile(
1819 &self,
1820 source_id: &str,
1821 tile_id: CanonicalTileId,
1822 ) -> Result<NativeFuture<CommandCompletion>> {
1823 let mut call = self.inner.call();
1824 let source_id = call.input(&source_id)?;
1825 let tile_id = call.input(&tile_id)?;
1826 call.command(|map, completion, out_diagnostic| unsafe {
1827 sys::mln_map_invalidate_custom_vector_source_tile(
1828 map,
1829 source_id,
1830 tile_id,
1831 completion,
1832 out_diagnostic,
1833 )
1834 })
1835 }
1836
1837 /// Computes the area that the map would show with `camera`.
1838 ///
1839 /// Camera fields that `camera` doesn't set come from the map's camera. The
1840 /// longitudes can fall outside -180 to 180, so a view across the
1841 /// antimeridian gives one continuous range.
1842 ///
1843 /// See `mln_map_lat_lng_bounds_for_camera` in the
1844 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
1845 pub fn lat_lng_bounds_for_camera(
1846 &self,
1847 camera: &CameraOptions,
1848 ) -> Result<NativeFuture<LatLngBounds>> {
1849 let mut call = self.inner.call();
1850 let camera = call.reference(&camera)?;
1851 call.complete(
1852 |map, completion, out_diagnostic| unsafe {
1853 sys::mln_map_lat_lng_bounds_for_camera(map, camera, completion, out_diagnostic)
1854 },
1855 completion::value::<sys::mln_lat_lng_bounds, _>,
1856 )
1857 }
1858
1859 /// Lists the layers of the map's style, from bottom to top.
1860 ///
1861 /// See `mln_map_list_style_layers` in the
1862 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1863 pub fn list_style_layers(&self) -> Result<NativeFuture<Vec<StyleLayerInfo>>> {
1864 let call = self.inner.call();
1865 call.complete(
1866 |map, completion, out_diagnostic| unsafe {
1867 sys::mln_map_list_style_layers(map, completion, out_diagnostic)
1868 },
1869 completion::list::<sys::mln_style_layer_info, _>,
1870 )
1871 }
1872
1873 /// Lists the sources of the map's style.
1874 ///
1875 /// See `mln_map_list_style_sources` in the
1876 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1877 pub fn list_style_sources(&self) -> Result<NativeFuture<Vec<StyleSourceInfo>>> {
1878 let call = self.inner.call();
1879 call.complete(
1880 |map, completion, out_diagnostic| unsafe {
1881 sys::mln_map_list_style_sources(map, completion, out_diagnostic)
1882 },
1883 completion::list::<sys::mln_style_source_info, _>,
1884 )
1885 }
1886
1887 /// Moves a layer of the map's style below the layer named
1888 /// `before_layer_id`, or above every layer when `before_layer_id` is empty.
1889 ///
1890 /// See `mln_map_move_style_layer` in the
1891 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1892 ///
1893 /// # Errors
1894 ///
1895 /// - `Status::NotFound` when the style has no layer named `layer_id` or
1896 /// `before_layer_id`.
1897 /// - `Status::InvalidState` while the style isn't loaded, as
1898 /// `MapHandle::set_style_url()` describes.
1899 pub fn move_style_layer(
1900 &self,
1901 layer_id: &str,
1902 before_layer_id: Option<&str>,
1903 ) -> Result<NativeFuture<CommandCompletion>> {
1904 let mut call = self.inner.call();
1905 let layer_id = call.input(&layer_id)?;
1906 let before_layer_id = call.input(&before_layer_id)?;
1907 call.command(|map, completion, out_diagnostic| unsafe {
1908 sys::mln_map_move_style_layer(
1909 map,
1910 layer_id,
1911 before_layer_id,
1912 completion,
1913 out_diagnostic,
1914 )
1915 })
1916 }
1917
1918 /// Releases the map.
1919 ///
1920 /// Detach the map's render session first.
1921 ///
1922 /// See `mln_map_release` in the
1923 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1924 pub fn release(self) -> std::result::Result<NativeFuture<()>, ReleaseError<Self>> {
1925 self.consume(|map| {
1926 let call = Call::new(map);
1927 call.complete(
1928 |map, completion, out_diagnostic| unsafe {
1929 sys::mln_map_release(map, completion, out_diagnostic)
1930 },
1931 completion::unit,
1932 )
1933 })
1934 }
1935
1936 /// Removes the feature state that `selector` selects.
1937 ///
1938 /// See `mln_map_remove_feature_state` in the
1939 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
1940 pub fn remove_feature_state(
1941 &self,
1942 selector: &FeatureStateSelector<'_>,
1943 ) -> Result<NativeFuture<CommandCompletion>> {
1944 let mut call = self.inner.call();
1945 let selector = call.reference(&selector)?;
1946 call.command(|map, completion, out_diagnostic| unsafe {
1947 sys::mln_map_remove_feature_state(map, selector, completion, out_diagnostic)
1948 })
1949 }
1950
1951 /// Removes an image from the map's style.
1952 ///
1953 /// See `mln_map_remove_style_image` in the
1954 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1955 ///
1956 /// # Errors
1957 ///
1958 /// - `Status::NotFound` when the style has no image named `image_id`.
1959 /// - `Status::InvalidState` while the style isn't loaded, as
1960 /// `MapHandle::set_style_url()` describes.
1961 pub fn remove_style_image(&self, image_id: &str) -> Result<NativeFuture<CommandCompletion>> {
1962 let mut call = self.inner.call();
1963 let image_id = call.input(&image_id)?;
1964 call.command(|map, completion, out_diagnostic| unsafe {
1965 sys::mln_map_remove_style_image(map, image_id, completion, out_diagnostic)
1966 })
1967 }
1968
1969 /// Removes a layer from the map's style.
1970 ///
1971 /// See `mln_map_remove_style_layer` in the
1972 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1973 ///
1974 /// # Errors
1975 ///
1976 /// - `Status::NotFound` when the style has no layer named `layer_id`.
1977 /// - `Status::InvalidState` while the style isn't loaded, as
1978 /// `MapHandle::set_style_url()` describes.
1979 pub fn remove_style_layer(&self, layer_id: &str) -> Result<NativeFuture<CommandCompletion>> {
1980 let mut call = self.inner.call();
1981 let layer_id = call.input(&layer_id)?;
1982 call.command(|map, completion, out_diagnostic| unsafe {
1983 sys::mln_map_remove_style_layer(map, layer_id, completion, out_diagnostic)
1984 })
1985 }
1986
1987 /// Removes a source from the map's style.
1988 ///
1989 /// See `mln_map_remove_style_source` in the
1990 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
1991 ///
1992 /// # Errors
1993 ///
1994 /// - `Status::NotFound` when the style has no source named `source_id`.
1995 /// - `Status::InvalidState` when a layer still uses the source, or while
1996 /// the style isn't loaded, as `MapHandle::set_style_url()` describes.
1997 pub fn remove_style_source(&self, source_id: &str) -> Result<NativeFuture<CommandCompletion>> {
1998 let mut call = self.inner.call();
1999 let source_id = call.input(&source_id)?;
2000 call.command(|map, completion, out_diagnostic| unsafe {
2001 sys::mln_map_remove_style_source(map, source_id, completion, out_diagnostic)
2002 })
2003 }
2004
2005 /// Renders a new frame of a continuous map, even when nothing changed.
2006 ///
2007 /// See `mln_map_request_repaint` in the
2008 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
2009 pub fn request_repaint(&self) -> Result<NativeFuture<CommandCompletion>> {
2010 let call = self.inner.call();
2011 call.command(|map, completion, out_diagnostic| unsafe {
2012 sys::mln_map_request_repaint(map, completion, out_diagnostic)
2013 })
2014 }
2015
2016 /// Renders a still image of a static or tile map.
2017 ///
2018 /// The map's render session draws the image once every resource that the
2019 /// image needs has loaded.
2020 ///
2021 /// See `mln_map_request_still_image` in the
2022 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
2023 ///
2024 /// # Errors
2025 ///
2026 /// - `Status::Cancelled` when the map is released before the image is done.
2027 /// - `Status::NativeError` when the style or a resource that the image
2028 /// needs fails to load.
2029 pub fn request_still_image(&self) -> Result<NativeFuture<()>> {
2030 let call = self.inner.call();
2031 call.complete(
2032 |map, completion, out_diagnostic| unsafe {
2033 sys::mln_map_request_still_image(map, completion, out_diagnostic)
2034 },
2035 completion::unit,
2036 )
2037 }
2038
2039 /// Sets the map's size.
2040 ///
2041 /// A map with a render session takes its size from the session, so resize
2042 /// the session with `RenderSessionHandle::resize()` instead.
2043 ///
2044 /// See `mln_map_resize` in the
2045 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
2046 ///
2047 /// # Errors
2048 ///
2049 /// - `Status::InvalidState` when the map has a render session.
2050 /// - `Status::InvalidState` when a render session attached to the map
2051 /// before the resize applied.
2052 pub fn resize(&self, logical_size: LogicalSize) -> Result<NativeFuture<CommandCompletion>> {
2053 let mut call = self.inner.call();
2054 let logical_size = call.input(&logical_size)?;
2055 call.command(|map, completion, out_diagnostic| unsafe {
2056 sys::mln_map_resize(map, logical_size, completion, out_diagnostic)
2057 })
2058 }
2059
2060 /// Limits the camera's center to an area, and its zoom and pitch to ranges.
2061 ///
2062 /// Limits that `options` doesn't set keep their current values. When the
2063 /// camera is outside the new limits, it moves inside them.
2064 ///
2065 /// See `mln_map_set_bounds` in the
2066 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2067 pub fn set_bounds(&self, options: &BoundOptions) -> Result<NativeFuture<CommandCompletion>> {
2068 let mut call = self.inner.call();
2069 let options = call.reference(&options)?;
2070 call.command(|map, completion, out_diagnostic| unsafe {
2071 sys::mln_map_set_bounds(map, options, completion, out_diagnostic)
2072 })
2073 }
2074
2075 /// Sets the data of a tile in a custom geometry source.
2076 ///
2077 /// `data` is a GeoJSON feature collection, feature, or geometry. The source
2078 /// ignores data for a tile that it hasn't asked for, or has since
2079 /// cancelled.
2080 ///
2081 /// See `mln_map_set_custom_geometry_source_tile_data` in the
2082 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2083 ///
2084 /// # Errors
2085 ///
2086 /// - `Status::NotFound` when the style has no source named `source_id`.
2087 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
2088 /// custom geometry source.
2089 pub fn set_custom_geometry_source_tile_data(
2090 &self,
2091 source_id: &str,
2092 tile_id: CanonicalTileId,
2093 data: &str,
2094 ) -> Result<NativeFuture<CommandCompletion>> {
2095 let mut call = self.inner.call();
2096 let source_id = call.input(&source_id)?;
2097 let tile_id = call.input(&tile_id)?;
2098 let data = call.input(&data)?;
2099 call.command(|map, completion, out_diagnostic| unsafe {
2100 sys::mln_map_set_custom_geometry_source_tile_data(
2101 map,
2102 source_id,
2103 tile_id,
2104 data,
2105 completion,
2106 out_diagnostic,
2107 )
2108 })
2109 }
2110
2111 /// Reports that a tile of a custom geometry source failed to load.
2112 ///
2113 /// See `mln_map_set_custom_geometry_source_tile_error` in the
2114 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2115 ///
2116 /// # Errors
2117 ///
2118 /// - `Status::NotFound` when the style has no source named `source_id`.
2119 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
2120 /// custom geometry source.
2121 pub fn set_custom_geometry_source_tile_error(
2122 &self,
2123 source_id: &str,
2124 tile_id: CanonicalTileId,
2125 message: &str,
2126 ) -> Result<NativeFuture<CommandCompletion>> {
2127 let mut call = self.inner.call();
2128 let source_id = call.input(&source_id)?;
2129 let tile_id = call.input(&tile_id)?;
2130 let message = call.input(&message)?;
2131 call.command(|map, completion, out_diagnostic| unsafe {
2132 sys::mln_map_set_custom_geometry_source_tile_error(
2133 map,
2134 source_id,
2135 tile_id,
2136 message,
2137 completion,
2138 out_diagnostic,
2139 )
2140 })
2141 }
2142
2143 /// Sets the data of a tile in a custom vector source.
2144 ///
2145 /// `data` is the tile, encoded as `encoding`. The source ignores data for a
2146 /// tile that it hasn't asked for, or has since cancelled.
2147 ///
2148 /// See `mln_map_set_custom_vector_source_tile_data` in the
2149 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2150 ///
2151 /// # Errors
2152 ///
2153 /// - `Status::NotFound` when the style has no source named `source_id`.
2154 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
2155 /// custom vector source.
2156 pub fn set_custom_vector_source_tile_data(
2157 &self,
2158 source_id: &str,
2159 tile_id: CanonicalTileId,
2160 encoding: StyleVectorTileEncoding,
2161 data: &[u8],
2162 ) -> Result<NativeFuture<CommandCompletion>> {
2163 let mut call = self.inner.call();
2164 let source_id = call.input(&source_id)?;
2165 let tile_id = call.input(&tile_id)?;
2166 let data = call.input(&data)?;
2167 call.command(|map, completion, out_diagnostic| unsafe {
2168 sys::mln_map_set_custom_vector_source_tile_data(
2169 map,
2170 source_id,
2171 tile_id,
2172 encoding.as_raw(),
2173 data,
2174 completion,
2175 out_diagnostic,
2176 )
2177 })
2178 }
2179
2180 /// Reports that a tile of a custom vector source failed to load.
2181 ///
2182 /// See `mln_map_set_custom_vector_source_tile_error` in the
2183 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2184 ///
2185 /// # Errors
2186 ///
2187 /// - `Status::NotFound` when the style has no source named `source_id`.
2188 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
2189 /// custom vector source.
2190 pub fn set_custom_vector_source_tile_error(
2191 &self,
2192 source_id: &str,
2193 tile_id: CanonicalTileId,
2194 message: &str,
2195 ) -> Result<NativeFuture<CommandCompletion>> {
2196 let mut call = self.inner.call();
2197 let source_id = call.input(&source_id)?;
2198 let tile_id = call.input(&tile_id)?;
2199 let message = call.input(&message)?;
2200 call.command(|map, completion, out_diagnostic| unsafe {
2201 sys::mln_map_set_custom_vector_source_tile_error(
2202 map,
2203 source_id,
2204 tile_id,
2205 message,
2206 completion,
2207 out_diagnostic,
2208 )
2209 })
2210 }
2211
2212 /// Draws debugging overlays, such as tile borders, on the map.
2213 ///
2214 /// `flags` replaces the overlays set before.
2215 ///
2216 /// See `mln_map_set_debug_flags` in the
2217 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2218 pub fn set_debug_flags(&self, flags: MapDebugFlag) -> Result<NativeFuture<CommandCompletion>> {
2219 let call = self.inner.call();
2220 call.command(|map, completion, out_diagnostic| unsafe {
2221 sys::mln_map_set_debug_flags(map, flags.bits(), completion, out_diagnostic)
2222 })
2223 }
2224
2225 /// Selects the events that the map reports.
2226 ///
2227 /// See `mln_map_set_event_mask` in the
2228 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
2229 pub fn set_event_mask(
2230 &self,
2231 mask: RuntimeEventFlag,
2232 ) -> Result<NativeFuture<CommandCompletion>> {
2233 let call = self.inner.call();
2234 call.command(|map, completion, out_diagnostic| unsafe {
2235 sys::mln_map_set_event_mask(map, mask.bits(), completion, out_diagnostic)
2236 })
2237 }
2238
2239 /// Merges `state` into the state of a feature.
2240 ///
2241 /// `state` is a JSON object. Its keys replace the same keys in the
2242 /// feature's state, and the other keys stay.
2243 ///
2244 /// See `mln_map_set_feature_state` in the
2245 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
2246 pub fn set_feature_state(
2247 &self,
2248 selector: &FeatureStateSelector<'_>,
2249 state: &str,
2250 ) -> Result<NativeFuture<CommandCompletion>> {
2251 let mut call = self.inner.call();
2252 let selector = call.reference(&selector)?;
2253 let state = call.input(&state)?;
2254 call.command(|map, completion, out_diagnostic| unsafe {
2255 sys::mln_map_set_feature_state(map, selector, state, completion, out_diagnostic)
2256 })
2257 }
2258
2259 /// Places the camera at a position and orientation in space.
2260 ///
2261 /// The map adjusts them to a camera that it can show. It stops running
2262 /// camera animations first, and their end handlers report
2263 /// `CameraTransitionOutcome::Cancelled`.
2264 ///
2265 /// See `mln_map_set_free_camera_options` in the
2266 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2267 pub fn set_free_camera_options(
2268 &self,
2269 options: &FreeCameraOptions,
2270 ) -> Result<NativeFuture<CommandCompletion>> {
2271 let mut call = self.inner.call();
2272 let options = call.reference(&options)?;
2273 call.command(|map, completion, out_diagnostic| unsafe {
2274 sys::mln_map_set_free_camera_options(map, options, completion, out_diagnostic)
2275 })
2276 }
2277
2278 /// Replaces the data of a GeoJSON source.
2279 ///
2280 /// `data` is a GeoJSON feature collection, feature, or geometry. The
2281 /// library prepares it for the source with the source's options, off the
2282 /// threads that the caller and the runtime use, and the command completes
2283 /// once the source holds it. Later commands don't wait for it. While the
2284 /// source is still preparing earlier data, only the newest data waits to
2285 /// follow it.
2286 ///
2287 /// With synchronous tiling on, as
2288 /// `MapHandle::set_geo_json_source_synchronous_tiling()` describes, the
2289 /// command prepares `data` before later commands run, so the data shows in
2290 /// the next frame.
2291 ///
2292 /// See `mln_map_set_geo_json_source_data` in the
2293 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2294 ///
2295 /// # Errors
2296 ///
2297 /// - `Status::NotFound` when the style has no source named `source_id`.
2298 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
2299 /// GeoJSON source, when `data` isn't valid GeoJSON, or when the source
2300 /// clusters and `data` isn't a feature collection of points. The source
2301 /// keeps its data.
2302 /// - `Status::Cancelled` when newer data for the source replaces `data`
2303 /// while it waits, or when the source's URL, its removal, a style load,
2304 /// or the map's release replaces the source's data before `data` is
2305 /// ready.
2306 /// - `Status::InvalidState` while the style isn't loaded, as
2307 /// `MapHandle::set_style_url()` describes.
2308 pub fn set_geo_json_source_data(
2309 &self,
2310 source_id: &str,
2311 data: &str,
2312 ) -> Result<NativeFuture<CommandCompletion>> {
2313 let mut call = self.inner.call();
2314 let source_id = call.input(&source_id)?;
2315 let data = call.input(&data)?;
2316 call.command(|map, completion, out_diagnostic| unsafe {
2317 sys::mln_map_set_geo_json_source_data(map, source_id, data, completion, out_diagnostic)
2318 })
2319 }
2320
2321 /// Sets whether a GeoJSON source builds its tiles while the map renders.
2322 ///
2323 /// Building tiles while the map renders, instead of in the background,
2324 /// makes new data show in the next frame. The setting replaces the
2325 /// `synchronousUpdate` member of the source's JSON, which defaults to
2326 /// false.
2327 ///
2328 /// See `mln_map_set_geo_json_source_synchronous_tiling` in the
2329 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2330 ///
2331 /// # Errors
2332 ///
2333 /// - `Status::NotFound` when the style has no source named `source_id`.
2334 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
2335 /// GeoJSON source.
2336 /// - `Status::InvalidState` while the style isn't loaded, as
2337 /// `MapHandle::set_style_url()` describes.
2338 pub fn set_geo_json_source_synchronous_tiling(
2339 &self,
2340 source_id: &str,
2341 enabled: bool,
2342 ) -> Result<NativeFuture<CommandCompletion>> {
2343 let mut call = self.inner.call();
2344 let source_id = call.input(&source_id)?;
2345 call.command(|map, completion, out_diagnostic| unsafe {
2346 sys::mln_map_set_geo_json_source_synchronous_tiling(
2347 map,
2348 source_id,
2349 enabled,
2350 completion,
2351 out_diagnostic,
2352 )
2353 })
2354 }
2355
2356 /// Makes a GeoJSON source load its data from `url`.
2357 ///
2358 /// See `mln_map_set_geo_json_source_url` in the
2359 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2360 ///
2361 /// # Errors
2362 ///
2363 /// - `Status::NotFound` when the style has no source named `source_id`.
2364 /// - `Status::InvalidArgument` when the source named `source_id` isn't a
2365 /// GeoJSON source.
2366 /// - `Status::InvalidState` while the style isn't loaded, as
2367 /// `MapHandle::set_style_url()` describes.
2368 pub fn set_geo_json_source_url(
2369 &self,
2370 source_id: &str,
2371 url: &str,
2372 ) -> Result<NativeFuture<CommandCompletion>> {
2373 let mut call = self.inner.call();
2374 let source_id = call.input(&source_id)?;
2375 let url = call.input(&url)?;
2376 call.command(|map, completion, out_diagnostic| unsafe {
2377 sys::mln_map_set_geo_json_source_url(map, source_id, url, completion, out_diagnostic)
2378 })
2379 }
2380
2381 /// Sets a value that the style's `global-state`
2382 /// \[expressions\](https://maplibre.org/maplibre-style-spec/expressions/)
2383 /// read.
2384 ///
2385 /// See `mln_map_set_global_state_property` in the
2386 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2387 ///
2388 /// # Errors
2389 ///
2390 /// - `Status::InvalidState` while the style isn't loaded, as
2391 /// `MapHandle::set_style_url()` describes.
2392 pub fn set_global_state_property(
2393 &self,
2394 property_name: &str,
2395 value: &str,
2396 ) -> Result<NativeFuture<CommandCompletion>> {
2397 let mut call = self.inner.call();
2398 let property_name = call.input(&property_name)?;
2399 let value = call.input(&value)?;
2400 call.command(|map, completion, out_diagnostic| unsafe {
2401 sys::mln_map_set_global_state_property(
2402 map,
2403 property_name,
2404 value,
2405 completion,
2406 out_diagnostic,
2407 )
2408 })
2409 }
2410
2411 /// Moves the image of an image source.
2412 ///
2413 /// `coordinates` are the image's four corners, clockwise from the top left.
2414 ///
2415 /// See `mln_map_set_image_source_coordinates` in the
2416 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2417 ///
2418 /// # Errors
2419 ///
2420 /// - `Status::NotFound` when the style has no source named `source_id`.
2421 /// - `Status::InvalidArgument` when the source named `source_id` isn't an
2422 /// image source.
2423 /// - `Status::InvalidState` while the style isn't loaded, as
2424 /// `MapHandle::set_style_url()` describes.
2425 pub fn set_image_source_coordinates(
2426 &self,
2427 source_id: &str,
2428 coordinates: &[LatLng],
2429 ) -> Result<NativeFuture<CommandCompletion>> {
2430 let mut call = self.inner.call();
2431 let coordinate_count = convert::count(coordinates.len())?;
2432 let source_id = call.input(&source_id)?;
2433 let coordinates = call.array(coordinates)?;
2434 call.command(|map, completion, out_diagnostic| unsafe {
2435 sys::mln_map_set_image_source_coordinates(
2436 map,
2437 source_id,
2438 coordinates,
2439 coordinate_count,
2440 completion,
2441 out_diagnostic,
2442 )
2443 })
2444 }
2445
2446 /// Replaces the image of an image source.
2447 ///
2448 /// See `mln_map_set_image_source_image` in the
2449 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2450 ///
2451 /// # Errors
2452 ///
2453 /// - `Status::NotFound` when the style has no source named `source_id`.
2454 /// - `Status::InvalidArgument` when the source named `source_id` isn't an
2455 /// image source.
2456 /// - `Status::InvalidState` while the style isn't loaded, as
2457 /// `MapHandle::set_style_url()` describes.
2458 pub fn set_image_source_image(
2459 &self,
2460 source_id: &str,
2461 image: &PremultipliedRgba8Image<'_>,
2462 ) -> Result<NativeFuture<CommandCompletion>> {
2463 let mut call = self.inner.call();
2464 let source_id = call.input(&source_id)?;
2465 let image = call.reference(&image)?;
2466 call.command(|map, completion, out_diagnostic| unsafe {
2467 sys::mln_map_set_image_source_image(map, source_id, image, completion, out_diagnostic)
2468 })
2469 }
2470
2471 /// Makes an image source load its image from `url`.
2472 ///
2473 /// See `mln_map_set_image_source_url` in the
2474 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2475 ///
2476 /// # Errors
2477 ///
2478 /// - `Status::NotFound` when the style has no source named `source_id`.
2479 /// - `Status::InvalidArgument` when the source named `source_id` isn't an
2480 /// image source.
2481 /// - `Status::InvalidState` while the style isn't loaded, as
2482 /// `MapHandle::set_style_url()` describes.
2483 pub fn set_image_source_url(
2484 &self,
2485 source_id: &str,
2486 url: &str,
2487 ) -> Result<NativeFuture<CommandCompletion>> {
2488 let mut call = self.inner.call();
2489 let source_id = call.input(&source_id)?;
2490 let url = call.input(&url)?;
2491 call.command(|map, completion, out_diagnostic| unsafe {
2492 sys::mln_map_set_image_source_url(map, source_id, url, completion, out_diagnostic)
2493 })
2494 }
2495
2496 /// Sets whether the map draws in perspective or axonometric projection, and
2497 /// how much it skews the view.
2498 ///
2499 /// Settings that `options` doesn't set keep their current values.
2500 ///
2501 /// See `mln_map_set_projection_mode` in the
2502 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2503 pub fn set_projection_mode(
2504 &self,
2505 options: &ProjectionModeOptions,
2506 ) -> Result<NativeFuture<CommandCompletion>> {
2507 let mut call = self.inner.call();
2508 let options = call.reference(&options)?;
2509 call.command(|map, completion, out_diagnostic| unsafe {
2510 sys::mln_map_set_projection_mode(map, options, completion, out_diagnostic)
2511 })
2512 }
2513
2514 /// Shows or hides an overlay of rendering statistics on the map.
2515 ///
2516 /// See `mln_map_set_rendering_stats_view_enabled` in the
2517 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2518 pub fn set_rendering_stats_view_enabled(
2519 &self,
2520 enabled: bool,
2521 ) -> Result<NativeFuture<CommandCompletion>> {
2522 let call = self.inner.call();
2523 call.command(|map, completion, out_diagnostic| unsafe {
2524 sys::mln_map_set_rendering_stats_view_enabled(map, enabled, completion, out_diagnostic)
2525 })
2526 }
2527
2528 /// Adds an image to the map's style, or replaces the image named
2529 /// `image_id`.
2530 ///
2531 /// See `mln_map_set_style_image` in the
2532 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2533 ///
2534 /// # Errors
2535 ///
2536 /// - `Status::InvalidState` while the style isn't loaded, as
2537 /// `MapHandle::set_style_url()` describes.
2538 pub fn set_style_image(
2539 &self,
2540 image_id: &str,
2541 image: &PremultipliedRgba8Image<'_>,
2542 options: Option<&StyleImageOptions>,
2543 ) -> Result<NativeFuture<CommandCompletion>> {
2544 let mut call = self.inner.call();
2545 let image_id = call.input(&image_id)?;
2546 let image = call.reference(&image)?;
2547 let options = call.optional_reference(options.as_ref())?;
2548 call.command(|map, completion, out_diagnostic| unsafe {
2549 sys::mln_map_set_style_image(map, image_id, image, options, completion, out_diagnostic)
2550 })
2551 }
2552
2553 /// Loads the map's style from `json`.
2554 ///
2555 /// The command completes once the style has parsed, and the map's style is
2556 /// then loaded, as `MapHandle::set_style_url()` describes. The style's
2557 /// sources, sprites, and glyphs load in the background.
2558 ///
2559 /// See `mln_map_set_style_json` in the
2560 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
2561 ///
2562 /// # Errors
2563 ///
2564 /// - `Status::NativeError` when `json` isn't a valid style. The map keeps
2565 /// its current style.
2566 pub fn set_style_json(&self, json: &str) -> Result<NativeFuture<CommandCompletion>> {
2567 let mut call = self.inner.call();
2568 let json = call.input(&json)?;
2569 call.command(|map, completion, out_diagnostic| unsafe {
2570 sys::mln_map_set_style_json(map, json, completion, out_diagnostic)
2571 })
2572 }
2573
2574 /// Sets a property of a layer in the map's style.
2575 ///
2576 /// `property_name` is one of the layer's layout or paint
2577 /// \[properties\](https://maplibre.org/maplibre-style-spec/layers/), or
2578 /// `filter`, `minzoom`, `maxzoom`, `source`, or `source-layer`. A null
2579 /// `value` resets any of these but `source` and `source-layer` to its
2580 /// default.
2581 ///
2582 /// See `mln_map_set_style_layer_property` in the
2583 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2584 ///
2585 /// # Errors
2586 ///
2587 /// - `Status::NotFound` when the style has no layer named `layer_id`.
2588 /// - `Status::InvalidState` while the style isn't loaded, as
2589 /// `MapHandle::set_style_url()` describes.
2590 pub fn set_style_layer_property(
2591 &self,
2592 layer_id: &str,
2593 property_name: &str,
2594 value: &str,
2595 ) -> Result<NativeFuture<CommandCompletion>> {
2596 let mut call = self.inner.call();
2597 let layer_id = call.input(&layer_id)?;
2598 let property_name = call.input(&property_name)?;
2599 let value = call.input(&value)?;
2600 call.command(|map, completion, out_diagnostic| unsafe {
2601 sys::mln_map_set_style_layer_property(
2602 map,
2603 layer_id,
2604 property_name,
2605 value,
2606 completion,
2607 out_diagnostic,
2608 )
2609 })
2610 }
2611
2612 /// Replaces the \[light\](https://maplibre.org/maplibre-style-spec/light/)
2613 /// of the map's style.
2614 ///
2615 /// See `mln_map_set_style_light_json` in the
2616 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2617 ///
2618 /// # Errors
2619 ///
2620 /// - `Status::InvalidState` while the style isn't loaded, as
2621 /// `MapHandle::set_style_url()` describes.
2622 pub fn set_style_light_json(
2623 &self,
2624 light_json: &str,
2625 ) -> Result<NativeFuture<CommandCompletion>> {
2626 let mut call = self.inner.call();
2627 let light_json = call.input(&light_json)?;
2628 call.command(|map, completion, out_diagnostic| unsafe {
2629 sys::mln_map_set_style_light_json(map, light_json, completion, out_diagnostic)
2630 })
2631 }
2632
2633 /// Sets a property of the light of the map's style.
2634 ///
2635 /// See `mln_map_set_style_light_property` in the
2636 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2637 ///
2638 /// # Errors
2639 ///
2640 /// - `Status::InvalidState` while the style isn't loaded, as
2641 /// `MapHandle::set_style_url()` describes.
2642 pub fn set_style_light_property(
2643 &self,
2644 property_name: &str,
2645 value: &str,
2646 ) -> Result<NativeFuture<CommandCompletion>> {
2647 let mut call = self.inner.call();
2648 let property_name = call.input(&property_name)?;
2649 let value = call.input(&value)?;
2650 call.command(|map, completion, out_diagnostic| unsafe {
2651 sys::mln_map_set_style_light_property(
2652 map,
2653 property_name,
2654 value,
2655 completion,
2656 out_diagnostic,
2657 )
2658 })
2659 }
2660
2661 /// Sets whether a source is volatile.
2662 ///
2663 /// The map doesn't store the tiles of a volatile source in the persistent
2664 /// cache.
2665 ///
2666 /// See `mln_map_set_style_source_volatile` in the
2667 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2668 ///
2669 /// # Errors
2670 ///
2671 /// - `Status::NotFound` when the style has no source named `source_id`.
2672 /// - `Status::InvalidState` while the style isn't loaded, as
2673 /// `MapHandle::set_style_url()` describes.
2674 pub fn set_style_source_volatile(
2675 &self,
2676 source_id: &str,
2677 is_volatile: bool,
2678 ) -> Result<NativeFuture<CommandCompletion>> {
2679 let mut call = self.inner.call();
2680 let source_id = call.input(&source_id)?;
2681 call.command(|map, completion, out_diagnostic| unsafe {
2682 sys::mln_map_set_style_source_volatile(
2683 map,
2684 source_id,
2685 is_volatile,
2686 completion,
2687 out_diagnostic,
2688 )
2689 })
2690 }
2691
2692 /// Sets the default transition of the map's style.
2693 ///
2694 /// See `mln_map_set_style_transition_options` in the
2695 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2696 ///
2697 /// # Errors
2698 ///
2699 /// - `Status::InvalidState` while the style isn't loaded, as
2700 /// `MapHandle::set_style_url()` describes.
2701 pub fn set_style_transition_options(
2702 &self,
2703 options: &StyleTransitionOptions,
2704 ) -> Result<NativeFuture<CommandCompletion>> {
2705 let mut call = self.inner.call();
2706 let options = call.reference(&options)?;
2707 call.command(|map, completion, out_diagnostic| unsafe {
2708 sys::mln_map_set_style_transition_options(map, options, completion, out_diagnostic)
2709 })
2710 }
2711
2712 /// Loads the map's style from `url`.
2713 ///
2714 /// The command completes once the style document has loaded and parsed. The
2715 /// style's sources, sprites, and glyphs then load in the background.
2716 ///
2717 /// The map's style is loaded from the time a style document parses until
2718 /// the next call to this function. While the style isn't loaded, the
2719 /// commands that change it complete with `Status::InvalidState`. To change
2720 /// a new map's style without a style document, first load an empty style,
2721 /// such as `{"version":8,"sources":{},"layers":[]}`.
2722 ///
2723 /// See `mln_map_set_style_url` in the
2724 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
2725 ///
2726 /// # Errors
2727 ///
2728 /// - `Status::NativeError` when the style document fails to load or isn't a
2729 /// valid style.
2730 /// - `Status::Cancelled` when the map is released, or this function or
2731 /// `MapHandle::set_style_json()` loads another style, before the style
2732 /// document parses.
2733 pub fn set_style_url(&self, url: &str) -> Result<NativeFuture<CommandCompletion>> {
2734 let mut call = self.inner.call();
2735 let url = call.input(&url)?;
2736 call.command(|map, completion, out_diagnostic| unsafe {
2737 sys::mln_map_set_style_url(map, url, completion, out_diagnostic)
2738 })
2739 }
2740
2741 /// Sets how the map chooses which tiles to load, and at what detail.
2742 ///
2743 /// Settings that `options` doesn't set keep their current values.
2744 ///
2745 /// See `mln_map_set_tile_options` in the
2746 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2747 pub fn set_tile_options(
2748 &self,
2749 options: &MapTileOptions,
2750 ) -> Result<NativeFuture<CommandCompletion>> {
2751 let mut call = self.inner.call();
2752 let options = call.reference(&options)?;
2753 call.command(|map, completion, out_diagnostic| unsafe {
2754 sys::mln_map_set_tile_options(map, options, completion, out_diagnostic)
2755 })
2756 }
2757
2758 /// Sets how the map orients and constrains its view.
2759 ///
2760 /// Settings that `options` doesn't set keep their current values.
2761 ///
2762 /// See `mln_map_set_viewport_options` in the
2763 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2764 pub fn set_viewport_options(
2765 &self,
2766 options: &MapViewportOptions,
2767 ) -> Result<NativeFuture<CommandCompletion>> {
2768 let mut call = self.inner.call();
2769 let options = call.reference(&options)?;
2770 call.command(|map, completion, out_diagnostic| unsafe {
2771 sys::mln_map_set_viewport_options(map, options, completion, out_diagnostic)
2772 })
2773 }
2774
2775 /// Moves the camera, at once or with an animation.
2776 ///
2777 /// Camera fields that `update` doesn't set keep their values, and the
2778 /// update stops any running animation of the fields it sets. The function
2779 /// finishes when the map applies the update, before an animation ends. To
2780 /// learn when an animation ends, set an `CameraTransitionHandler` in its
2781 /// animation options.
2782 ///
2783 /// See `mln_map_update_camera` in the
2784 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2785 pub fn update_camera(&self, update: &CameraUpdate) -> Result<NativeFuture<CommandCompletion>> {
2786 let mut call = self.inner.call();
2787 let update = call.reference(&update)?;
2788 call.command(|map, completion, out_diagnostic| unsafe {
2789 sys::mln_map_update_camera(map, update, completion, out_diagnostic)
2790 })
2791 }
2792}
2793
2794/// Submits [`MapHandle`] commands without a completion. Each call returns
2795/// the same acceptance status as its completing form, and native logs a
2796/// command that later fails as a warning through the log handler.
2797pub struct MapHandleDiscarding<'a>(&'a MapHandle);
2798impl MapHandle {
2799 pub fn discarding(&self) -> MapHandleDiscarding<'_> {
2800 MapHandleDiscarding(self)
2801 }
2802}
2803impl MapHandleDiscarding<'_> {
2804 /// Adds a source whose GeoJSON tiles come from callbacks.
2805 ///
2806 /// See `mln_map_add_custom_geometry_source` in the
2807 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2808 pub fn add_custom_geometry_source(
2809 &self,
2810 source_id: &str,
2811 options: CustomGeometrySourceOptions,
2812 ) -> Result<()> {
2813 let mut call = self.0.inner.call();
2814 let source_id = call.input(&source_id)?;
2815 let options = call.reference(&options)?;
2816 call.discard(|map, completion, out_diagnostic| unsafe {
2817 sys::mln_map_add_custom_geometry_source(
2818 map,
2819 source_id,
2820 options,
2821 completion,
2822 out_diagnostic,
2823 )
2824 })
2825 }
2826
2827 /// Adds a source whose vector tiles come from callbacks.
2828 ///
2829 /// See `mln_map_add_custom_vector_source` in the
2830 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2831 pub fn add_custom_vector_source(
2832 &self,
2833 source_id: &str,
2834 options: CustomVectorSourceOptions,
2835 ) -> Result<()> {
2836 let mut call = self.0.inner.call();
2837 let source_id = call.input(&source_id)?;
2838 let options = call.reference(&options)?;
2839 call.discard(|map, completion, out_diagnostic| unsafe {
2840 sys::mln_map_add_custom_vector_source(
2841 map,
2842 source_id,
2843 options,
2844 completion,
2845 out_diagnostic,
2846 )
2847 })
2848 }
2849
2850 /// Adds a GeoJSON source with no data.
2851 ///
2852 /// Give it data with `MapHandle::set_geo_json_source_data()` or
2853 /// `MapHandle::set_geo_json_source_url()`. Its options stay fixed for as
2854 /// long as the style holds it.
2855 ///
2856 /// `attribution` is the source's
2857 /// \[attribution\](https://maplibre.org/maplibre-style-spec/sources/#attribution),
2858 /// or empty for none.
2859 ///
2860 /// See `mln_map_add_geo_json_source` in the
2861 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2862 ///
2863 /// # Errors
2864 ///
2865 /// - `Status::InvalidArgument` when an option in `options` is out of range.
2866 pub fn add_geo_json_source(
2867 &self,
2868 source_id: &str,
2869 options: Option<&GeoJsonSourceOptions>,
2870 attribution: Option<&str>,
2871 ) -> Result<()> {
2872 let mut call = self.0.inner.call();
2873 let source_id = call.input(&source_id)?;
2874 let options = call.optional_reference(options.as_ref())?;
2875 let attribution = call.input(&attribution)?;
2876 call.discard(|map, completion, out_diagnostic| unsafe {
2877 sys::mln_map_add_geo_json_source(
2878 map,
2879 source_id,
2880 options,
2881 attribution,
2882 completion,
2883 out_diagnostic,
2884 )
2885 })
2886 }
2887
2888 /// Adds an image source that shows `image`.
2889 ///
2890 /// `coordinates` are the image's four corners, clockwise from the top left.
2891 ///
2892 /// See `mln_map_add_image_source_image` in the
2893 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2894 pub fn add_image_source_image(
2895 &self,
2896 source_id: &str,
2897 coordinates: &[LatLng],
2898 image: &PremultipliedRgba8Image<'_>,
2899 ) -> Result<()> {
2900 let mut call = self.0.inner.call();
2901 let coordinate_count = convert::count(coordinates.len())?;
2902 let source_id = call.input(&source_id)?;
2903 let coordinates = call.array(coordinates)?;
2904 let image = call.reference(&image)?;
2905 call.discard(|map, completion, out_diagnostic| unsafe {
2906 sys::mln_map_add_image_source_image(
2907 map,
2908 source_id,
2909 coordinates,
2910 coordinate_count,
2911 image,
2912 completion,
2913 out_diagnostic,
2914 )
2915 })
2916 }
2917
2918 /// Adds a layer to the map's style.
2919 ///
2920 /// `layer_json` is a
2921 /// \[layer\](https://maplibre.org/maplibre-style-spec/layers/) object. The
2922 /// layer goes below the layer named `before_layer_id`, or above every layer
2923 /// when `before_layer_id` is empty.
2924 ///
2925 /// See `mln_map_add_style_layer_json` in the
2926 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2927 pub fn add_style_layer_json(
2928 &self,
2929 layer_json: &str,
2930 before_layer_id: Option<&str>,
2931 ) -> Result<()> {
2932 let mut call = self.0.inner.call();
2933 let layer_json = call.input(&layer_json)?;
2934 let before_layer_id = call.input(&before_layer_id)?;
2935 call.discard(|map, completion, out_diagnostic| unsafe {
2936 sys::mln_map_add_style_layer_json(
2937 map,
2938 layer_json,
2939 before_layer_id,
2940 completion,
2941 out_diagnostic,
2942 )
2943 })
2944 }
2945
2946 /// Adds a source to the map's style.
2947 ///
2948 /// `source_json` is a
2949 /// \[source\](https://maplibre.org/maplibre-style-spec/sources/) object.
2950 ///
2951 /// See `mln_map_add_style_source_json` in the
2952 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
2953 pub fn add_style_source_json(&self, source_id: &str, source_json: &str) -> Result<()> {
2954 let mut call = self.0.inner.call();
2955 let source_id = call.input(&source_id)?;
2956 let source_json = call.input(&source_json)?;
2957 call.discard(|map, completion, out_diagnostic| unsafe {
2958 sys::mln_map_add_style_source_json(
2959 map,
2960 source_id,
2961 source_json,
2962 completion,
2963 out_diagnostic,
2964 )
2965 })
2966 }
2967
2968 /// Moves the camera relative to where it is, as a gesture does.
2969 ///
2970 /// `delta` can pan the map's content by an offset on the screen, scale the
2971 /// zoom, and add to the bearing and pitch. An anchor keeps one screen point
2972 /// in place while the scale, bearing, or pitch changes. An anchor needs one
2973 /// of those changes, and combines with an offset only when the delta has no
2974 /// animation. The function finishes when the map applies the delta, before
2975 /// an animation ends.
2976 ///
2977 /// A delta that replaces an animated one starts from where that animation
2978 /// left the camera, so the rest of the replaced change never happens. To
2979 /// reach an exact camera, use `MapHandle::update_camera()`.
2980 ///
2981 /// A delta in the end phase can carry momentum, which keeps the camera
2982 /// moving from the gesture's release velocities and slows it on each
2983 /// rendered frame. The gesture lasts until the momentum ends: the snapshot
2984 /// keeps `gesture_in_progress` set, and camera events report
2985 /// `CameraChangeSource::Momentum`. With momentum, `animation` sets only
2986 /// `transition_id` and the end handler, which runs when the gesture ends.
2987 ///
2988 /// A delta in the begin phase, `MapHandle::cancel_camera_transitions()`, or
2989 /// a cancellation by that ID stops the momentum. A later command that sets
2990 /// a field stops only the parts of the momentum that move that field. On a
2991 /// tilted map, the pan moves the map's content the same distance on the
2992 /// screen in every direction.
2993 ///
2994 /// See `mln_map_apply_camera_delta` in the
2995 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
2996 pub fn apply_camera_delta(&self, delta: &CameraDelta) -> Result<()> {
2997 let mut call = self.0.inner.call();
2998 let delta = call.reference(&delta)?;
2999 call.discard(|map, completion, out_diagnostic| unsafe {
3000 sys::mln_map_apply_camera_delta(map, delta, completion, out_diagnostic)
3001 })
3002 }
3003
3004 /// Holds back the map's changes from rendering until
3005 /// `MapHandle::end_command_group()`, so they show in the same frame.
3006 ///
3007 /// Groups nest, and the changes render when the outermost group ends.
3008 ///
3009 /// See `mln_map_begin_command_group` in the
3010 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3011 pub fn begin_command_group(&self) -> Result<()> {
3012 let call = self.0.inner.call();
3013 call.discard(|map, completion, out_diagnostic| unsafe {
3014 sys::mln_map_begin_command_group(map, completion, out_diagnostic)
3015 })
3016 }
3017
3018 /// Stops every running camera animation where it is.
3019 ///
3020 /// The end handler of each stopped animation reports
3021 /// `CameraTransitionOutcome::Cancelled`.
3022 ///
3023 /// See `mln_map_cancel_camera_transitions` in the
3024 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3025 pub fn cancel_camera_transitions(&self) -> Result<()> {
3026 let call = self.0.inner.call();
3027 call.discard(|map, completion, out_diagnostic| unsafe {
3028 sys::mln_map_cancel_camera_transitions(map, completion, out_diagnostic)
3029 })
3030 }
3031
3032 /// Stops the running camera animations whose animation options set
3033 /// `transition_id`.
3034 ///
3035 /// Other animations keep running. The end handler of each stopped animation
3036 /// reports `CameraTransitionOutcome::Cancelled`.
3037 ///
3038 /// See `mln_map_cancel_camera_transitions_with_id` in the
3039 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3040 pub fn cancel_camera_transitions_with_id(&self, transition_id: u64) -> Result<()> {
3041 let call = self.0.inner.call();
3042 call.discard(|map, completion, out_diagnostic| unsafe {
3043 sys::mln_map_cancel_camera_transitions_with_id(
3044 map,
3045 transition_id,
3046 completion,
3047 out_diagnostic,
3048 )
3049 })
3050 }
3051
3052 /// Logs debugging information about the map's style and sources.
3053 ///
3054 /// See `mln_map_dump_debug_logs` in the
3055 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3056 pub fn dump_debug_logs(&self) -> Result<()> {
3057 let call = self.0.inner.call();
3058 call.discard(|map, completion, out_diagnostic| unsafe {
3059 sys::mln_map_dump_debug_logs(map, completion, out_diagnostic)
3060 })
3061 }
3062
3063 /// Ends the group that `MapHandle::begin_command_group()` began.
3064 ///
3065 /// See `mln_map_end_command_group` in the
3066 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3067 pub fn end_command_group(&self) -> Result<()> {
3068 let call = self.0.inner.call();
3069 call.discard(|map, completion, out_diagnostic| unsafe {
3070 sys::mln_map_end_command_group(map, completion, out_diagnostic)
3071 })
3072 }
3073
3074 /// Moves the camera to fit a GeoJSON geometry in the map's view, at once or
3075 /// with an animation.
3076 ///
3077 /// `geometry` is a GeoJSON geometry object with at least one coordinate,
3078 /// not a feature. The camera is the one that
3079 /// `MapHandle::camera_for_geometry()` computes after the commands sent
3080 /// before this one apply. The function finishes when the map applies the
3081 /// change, before an animation ends.
3082 ///
3083 /// See `mln_map_fit_camera_to_geometry` in the
3084 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3085 pub fn fit_camera_to_geometry(&self, geometry: &str, update: &CameraFitUpdate) -> Result<()> {
3086 let mut call = self.0.inner.call();
3087 let geometry = call.input(&geometry)?;
3088 let update = call.reference(&update)?;
3089 call.discard(|map, completion, out_diagnostic| unsafe {
3090 sys::mln_map_fit_camera_to_geometry(map, geometry, update, completion, out_diagnostic)
3091 })
3092 }
3093
3094 /// Moves the camera to fit `bounds` in the map's view, at once or with an
3095 /// animation.
3096 ///
3097 /// The camera is the one that `MapHandle::camera_for_lat_lng_bounds()`
3098 /// computes after the commands sent before this one apply. The function
3099 /// finishes when the map applies the change, before an animation ends.
3100 ///
3101 /// See `mln_map_fit_camera_to_lat_lng_bounds` in the
3102 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3103 pub fn fit_camera_to_lat_lng_bounds(
3104 &self,
3105 bounds: LatLngBounds,
3106 update: &CameraFitUpdate,
3107 ) -> Result<()> {
3108 let mut call = self.0.inner.call();
3109 let bounds = call.input(&bounds)?;
3110 let update = call.reference(&update)?;
3111 call.discard(|map, completion, out_diagnostic| unsafe {
3112 sys::mln_map_fit_camera_to_lat_lng_bounds(
3113 map,
3114 bounds,
3115 update,
3116 completion,
3117 out_diagnostic,
3118 )
3119 })
3120 }
3121
3122 /// Moves the camera to fit `coordinates` in the map's view, at once or with
3123 /// an animation.
3124 ///
3125 /// `coordinates` must not be empty. The camera is the one that
3126 /// `MapHandle::camera_for_lat_lngs()` computes after the commands sent
3127 /// before this one apply. The function finishes when the map applies the
3128 /// change, before an animation ends.
3129 ///
3130 /// See `mln_map_fit_camera_to_lat_lngs` in the
3131 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3132 pub fn fit_camera_to_lat_lngs(
3133 &self,
3134 coordinates: &[LatLng],
3135 update: &CameraFitUpdate,
3136 ) -> Result<()> {
3137 let mut call = self.0.inner.call();
3138 let coordinate_count = convert::count(coordinates.len())?;
3139 let coordinates = call.array(coordinates)?;
3140 let update = call.reference(&update)?;
3141 call.discard(|map, completion, out_diagnostic| unsafe {
3142 sys::mln_map_fit_camera_to_lat_lngs(
3143 map,
3144 coordinates,
3145 coordinate_count,
3146 update,
3147 completion,
3148 out_diagnostic,
3149 )
3150 })
3151 }
3152
3153 /// Makes a custom geometry source ask again for the tiles in `bounds` that
3154 /// the map still needs.
3155 ///
3156 /// See `mln_map_invalidate_custom_geometry_source_region` in the
3157 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3158 pub fn invalidate_custom_geometry_source_region(
3159 &self,
3160 source_id: &str,
3161 bounds: LatLngBounds,
3162 ) -> Result<()> {
3163 let mut call = self.0.inner.call();
3164 let source_id = call.input(&source_id)?;
3165 let bounds = call.input(&bounds)?;
3166 call.discard(|map, completion, out_diagnostic| unsafe {
3167 sys::mln_map_invalidate_custom_geometry_source_region(
3168 map,
3169 source_id,
3170 bounds,
3171 completion,
3172 out_diagnostic,
3173 )
3174 })
3175 }
3176
3177 /// Makes a custom geometry source ask for a tile again when the map needs
3178 /// it.
3179 ///
3180 /// See `mln_map_invalidate_custom_geometry_source_tile` in the
3181 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3182 pub fn invalidate_custom_geometry_source_tile(
3183 &self,
3184 source_id: &str,
3185 tile_id: CanonicalTileId,
3186 ) -> Result<()> {
3187 let mut call = self.0.inner.call();
3188 let source_id = call.input(&source_id)?;
3189 let tile_id = call.input(&tile_id)?;
3190 call.discard(|map, completion, out_diagnostic| unsafe {
3191 sys::mln_map_invalidate_custom_geometry_source_tile(
3192 map,
3193 source_id,
3194 tile_id,
3195 completion,
3196 out_diagnostic,
3197 )
3198 })
3199 }
3200
3201 /// Makes a custom vector source ask again for the tiles in `bounds` that
3202 /// the map still needs.
3203 ///
3204 /// See `mln_map_invalidate_custom_vector_source_region` in the
3205 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3206 pub fn invalidate_custom_vector_source_region(
3207 &self,
3208 source_id: &str,
3209 bounds: LatLngBounds,
3210 ) -> Result<()> {
3211 let mut call = self.0.inner.call();
3212 let source_id = call.input(&source_id)?;
3213 let bounds = call.input(&bounds)?;
3214 call.discard(|map, completion, out_diagnostic| unsafe {
3215 sys::mln_map_invalidate_custom_vector_source_region(
3216 map,
3217 source_id,
3218 bounds,
3219 completion,
3220 out_diagnostic,
3221 )
3222 })
3223 }
3224
3225 /// Makes a custom vector source ask for a tile again when the map needs it.
3226 ///
3227 /// See `mln_map_invalidate_custom_vector_source_tile` in the
3228 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3229 pub fn invalidate_custom_vector_source_tile(
3230 &self,
3231 source_id: &str,
3232 tile_id: CanonicalTileId,
3233 ) -> Result<()> {
3234 let mut call = self.0.inner.call();
3235 let source_id = call.input(&source_id)?;
3236 let tile_id = call.input(&tile_id)?;
3237 call.discard(|map, completion, out_diagnostic| unsafe {
3238 sys::mln_map_invalidate_custom_vector_source_tile(
3239 map,
3240 source_id,
3241 tile_id,
3242 completion,
3243 out_diagnostic,
3244 )
3245 })
3246 }
3247
3248 /// Moves a layer of the map's style below the layer named
3249 /// `before_layer_id`, or above every layer when `before_layer_id` is empty.
3250 ///
3251 /// See `mln_map_move_style_layer` in the
3252 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3253 pub fn move_style_layer(&self, layer_id: &str, before_layer_id: Option<&str>) -> Result<()> {
3254 let mut call = self.0.inner.call();
3255 let layer_id = call.input(&layer_id)?;
3256 let before_layer_id = call.input(&before_layer_id)?;
3257 call.discard(|map, completion, out_diagnostic| unsafe {
3258 sys::mln_map_move_style_layer(
3259 map,
3260 layer_id,
3261 before_layer_id,
3262 completion,
3263 out_diagnostic,
3264 )
3265 })
3266 }
3267
3268 /// Removes the feature state that `selector` selects.
3269 ///
3270 /// See `mln_map_remove_feature_state` in the
3271 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3272 pub fn remove_feature_state(&self, selector: &FeatureStateSelector<'_>) -> Result<()> {
3273 let mut call = self.0.inner.call();
3274 let selector = call.reference(&selector)?;
3275 call.discard(|map, completion, out_diagnostic| unsafe {
3276 sys::mln_map_remove_feature_state(map, selector, completion, out_diagnostic)
3277 })
3278 }
3279
3280 /// Removes an image from the map's style.
3281 ///
3282 /// See `mln_map_remove_style_image` in the
3283 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3284 pub fn remove_style_image(&self, image_id: &str) -> Result<()> {
3285 let mut call = self.0.inner.call();
3286 let image_id = call.input(&image_id)?;
3287 call.discard(|map, completion, out_diagnostic| unsafe {
3288 sys::mln_map_remove_style_image(map, image_id, completion, out_diagnostic)
3289 })
3290 }
3291
3292 /// Removes a layer from the map's style.
3293 ///
3294 /// See `mln_map_remove_style_layer` in the
3295 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3296 pub fn remove_style_layer(&self, layer_id: &str) -> Result<()> {
3297 let mut call = self.0.inner.call();
3298 let layer_id = call.input(&layer_id)?;
3299 call.discard(|map, completion, out_diagnostic| unsafe {
3300 sys::mln_map_remove_style_layer(map, layer_id, completion, out_diagnostic)
3301 })
3302 }
3303
3304 /// Removes a source from the map's style.
3305 ///
3306 /// See `mln_map_remove_style_source` in the
3307 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3308 pub fn remove_style_source(&self, source_id: &str) -> Result<()> {
3309 let mut call = self.0.inner.call();
3310 let source_id = call.input(&source_id)?;
3311 call.discard(|map, completion, out_diagnostic| unsafe {
3312 sys::mln_map_remove_style_source(map, source_id, completion, out_diagnostic)
3313 })
3314 }
3315
3316 /// Renders a new frame of a continuous map, even when nothing changed.
3317 ///
3318 /// See `mln_map_request_repaint` in the
3319 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3320 pub fn request_repaint(&self) -> Result<()> {
3321 let call = self.0.inner.call();
3322 call.discard(|map, completion, out_diagnostic| unsafe {
3323 sys::mln_map_request_repaint(map, completion, out_diagnostic)
3324 })
3325 }
3326
3327 /// Sets the map's size.
3328 ///
3329 /// A map with a render session takes its size from the session, so resize
3330 /// the session with `RenderSessionHandle::resize()` instead.
3331 ///
3332 /// See `mln_map_resize` in the
3333 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3334 ///
3335 /// # Errors
3336 ///
3337 /// - `Status::InvalidState` when the map has a render session.
3338 pub fn resize(&self, logical_size: LogicalSize) -> Result<()> {
3339 let mut call = self.0.inner.call();
3340 let logical_size = call.input(&logical_size)?;
3341 call.discard(|map, completion, out_diagnostic| unsafe {
3342 sys::mln_map_resize(map, logical_size, completion, out_diagnostic)
3343 })
3344 }
3345
3346 /// Limits the camera's center to an area, and its zoom and pitch to ranges.
3347 ///
3348 /// Limits that `options` doesn't set keep their current values. When the
3349 /// camera is outside the new limits, it moves inside them.
3350 ///
3351 /// See `mln_map_set_bounds` in the
3352 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3353 pub fn set_bounds(&self, options: &BoundOptions) -> Result<()> {
3354 let mut call = self.0.inner.call();
3355 let options = call.reference(&options)?;
3356 call.discard(|map, completion, out_diagnostic| unsafe {
3357 sys::mln_map_set_bounds(map, options, completion, out_diagnostic)
3358 })
3359 }
3360
3361 /// Sets the data of a tile in a custom geometry source.
3362 ///
3363 /// `data` is a GeoJSON feature collection, feature, or geometry. The source
3364 /// ignores data for a tile that it hasn't asked for, or has since
3365 /// cancelled.
3366 ///
3367 /// See `mln_map_set_custom_geometry_source_tile_data` in the
3368 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3369 pub fn set_custom_geometry_source_tile_data(
3370 &self,
3371 source_id: &str,
3372 tile_id: CanonicalTileId,
3373 data: &str,
3374 ) -> Result<()> {
3375 let mut call = self.0.inner.call();
3376 let source_id = call.input(&source_id)?;
3377 let tile_id = call.input(&tile_id)?;
3378 let data = call.input(&data)?;
3379 call.discard(|map, completion, out_diagnostic| unsafe {
3380 sys::mln_map_set_custom_geometry_source_tile_data(
3381 map,
3382 source_id,
3383 tile_id,
3384 data,
3385 completion,
3386 out_diagnostic,
3387 )
3388 })
3389 }
3390
3391 /// Reports that a tile of a custom geometry source failed to load.
3392 ///
3393 /// See `mln_map_set_custom_geometry_source_tile_error` in the
3394 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3395 pub fn set_custom_geometry_source_tile_error(
3396 &self,
3397 source_id: &str,
3398 tile_id: CanonicalTileId,
3399 message: &str,
3400 ) -> Result<()> {
3401 let mut call = self.0.inner.call();
3402 let source_id = call.input(&source_id)?;
3403 let tile_id = call.input(&tile_id)?;
3404 let message = call.input(&message)?;
3405 call.discard(|map, completion, out_diagnostic| unsafe {
3406 sys::mln_map_set_custom_geometry_source_tile_error(
3407 map,
3408 source_id,
3409 tile_id,
3410 message,
3411 completion,
3412 out_diagnostic,
3413 )
3414 })
3415 }
3416
3417 /// Sets the data of a tile in a custom vector source.
3418 ///
3419 /// `data` is the tile, encoded as `encoding`. The source ignores data for a
3420 /// tile that it hasn't asked for, or has since cancelled.
3421 ///
3422 /// See `mln_map_set_custom_vector_source_tile_data` in the
3423 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3424 pub fn set_custom_vector_source_tile_data(
3425 &self,
3426 source_id: &str,
3427 tile_id: CanonicalTileId,
3428 encoding: StyleVectorTileEncoding,
3429 data: &[u8],
3430 ) -> Result<()> {
3431 let mut call = self.0.inner.call();
3432 let source_id = call.input(&source_id)?;
3433 let tile_id = call.input(&tile_id)?;
3434 let data = call.input(&data)?;
3435 call.discard(|map, completion, out_diagnostic| unsafe {
3436 sys::mln_map_set_custom_vector_source_tile_data(
3437 map,
3438 source_id,
3439 tile_id,
3440 encoding.as_raw(),
3441 data,
3442 completion,
3443 out_diagnostic,
3444 )
3445 })
3446 }
3447
3448 /// Reports that a tile of a custom vector source failed to load.
3449 ///
3450 /// See `mln_map_set_custom_vector_source_tile_error` in the
3451 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3452 pub fn set_custom_vector_source_tile_error(
3453 &self,
3454 source_id: &str,
3455 tile_id: CanonicalTileId,
3456 message: &str,
3457 ) -> Result<()> {
3458 let mut call = self.0.inner.call();
3459 let source_id = call.input(&source_id)?;
3460 let tile_id = call.input(&tile_id)?;
3461 let message = call.input(&message)?;
3462 call.discard(|map, completion, out_diagnostic| unsafe {
3463 sys::mln_map_set_custom_vector_source_tile_error(
3464 map,
3465 source_id,
3466 tile_id,
3467 message,
3468 completion,
3469 out_diagnostic,
3470 )
3471 })
3472 }
3473
3474 /// Draws debugging overlays, such as tile borders, on the map.
3475 ///
3476 /// `flags` replaces the overlays set before.
3477 ///
3478 /// See `mln_map_set_debug_flags` in the
3479 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3480 pub fn set_debug_flags(&self, flags: MapDebugFlag) -> Result<()> {
3481 let call = self.0.inner.call();
3482 call.discard(|map, completion, out_diagnostic| unsafe {
3483 sys::mln_map_set_debug_flags(map, flags.bits(), completion, out_diagnostic)
3484 })
3485 }
3486
3487 /// Selects the events that the map reports.
3488 ///
3489 /// See `mln_map_set_event_mask` in the
3490 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3491 pub fn set_event_mask(&self, mask: RuntimeEventFlag) -> Result<()> {
3492 let call = self.0.inner.call();
3493 call.discard(|map, completion, out_diagnostic| unsafe {
3494 sys::mln_map_set_event_mask(map, mask.bits(), completion, out_diagnostic)
3495 })
3496 }
3497
3498 /// Merges `state` into the state of a feature.
3499 ///
3500 /// `state` is a JSON object. Its keys replace the same keys in the
3501 /// feature's state, and the other keys stay.
3502 ///
3503 /// See `mln_map_set_feature_state` in the
3504 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3505 pub fn set_feature_state(
3506 &self,
3507 selector: &FeatureStateSelector<'_>,
3508 state: &str,
3509 ) -> Result<()> {
3510 let mut call = self.0.inner.call();
3511 let selector = call.reference(&selector)?;
3512 let state = call.input(&state)?;
3513 call.discard(|map, completion, out_diagnostic| unsafe {
3514 sys::mln_map_set_feature_state(map, selector, state, completion, out_diagnostic)
3515 })
3516 }
3517
3518 /// Places the camera at a position and orientation in space.
3519 ///
3520 /// The map adjusts them to a camera that it can show. It stops running
3521 /// camera animations first, and their end handlers report
3522 /// `CameraTransitionOutcome::Cancelled`.
3523 ///
3524 /// See `mln_map_set_free_camera_options` in the
3525 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3526 pub fn set_free_camera_options(&self, options: &FreeCameraOptions) -> Result<()> {
3527 let mut call = self.0.inner.call();
3528 let options = call.reference(&options)?;
3529 call.discard(|map, completion, out_diagnostic| unsafe {
3530 sys::mln_map_set_free_camera_options(map, options, completion, out_diagnostic)
3531 })
3532 }
3533
3534 /// Replaces the data of a GeoJSON source.
3535 ///
3536 /// `data` is a GeoJSON feature collection, feature, or geometry. The
3537 /// library prepares it for the source with the source's options, off the
3538 /// threads that the caller and the runtime use, and the command completes
3539 /// once the source holds it. Later commands don't wait for it. While the
3540 /// source is still preparing earlier data, only the newest data waits to
3541 /// follow it.
3542 ///
3543 /// With synchronous tiling on, as
3544 /// `MapHandle::set_geo_json_source_synchronous_tiling()` describes, the
3545 /// command prepares `data` before later commands run, so the data shows in
3546 /// the next frame.
3547 ///
3548 /// See `mln_map_set_geo_json_source_data` in the
3549 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3550 pub fn set_geo_json_source_data(&self, source_id: &str, data: &str) -> Result<()> {
3551 let mut call = self.0.inner.call();
3552 let source_id = call.input(&source_id)?;
3553 let data = call.input(&data)?;
3554 call.discard(|map, completion, out_diagnostic| unsafe {
3555 sys::mln_map_set_geo_json_source_data(map, source_id, data, completion, out_diagnostic)
3556 })
3557 }
3558
3559 /// Sets whether a GeoJSON source builds its tiles while the map renders.
3560 ///
3561 /// Building tiles while the map renders, instead of in the background,
3562 /// makes new data show in the next frame. The setting replaces the
3563 /// `synchronousUpdate` member of the source's JSON, which defaults to
3564 /// false.
3565 ///
3566 /// See `mln_map_set_geo_json_source_synchronous_tiling` in the
3567 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3568 pub fn set_geo_json_source_synchronous_tiling(
3569 &self,
3570 source_id: &str,
3571 enabled: bool,
3572 ) -> Result<()> {
3573 let mut call = self.0.inner.call();
3574 let source_id = call.input(&source_id)?;
3575 call.discard(|map, completion, out_diagnostic| unsafe {
3576 sys::mln_map_set_geo_json_source_synchronous_tiling(
3577 map,
3578 source_id,
3579 enabled,
3580 completion,
3581 out_diagnostic,
3582 )
3583 })
3584 }
3585
3586 /// Makes a GeoJSON source load its data from `url`.
3587 ///
3588 /// See `mln_map_set_geo_json_source_url` in the
3589 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3590 pub fn set_geo_json_source_url(&self, source_id: &str, url: &str) -> Result<()> {
3591 let mut call = self.0.inner.call();
3592 let source_id = call.input(&source_id)?;
3593 let url = call.input(&url)?;
3594 call.discard(|map, completion, out_diagnostic| unsafe {
3595 sys::mln_map_set_geo_json_source_url(map, source_id, url, completion, out_diagnostic)
3596 })
3597 }
3598
3599 /// Sets a value that the style's `global-state`
3600 /// \[expressions\](https://maplibre.org/maplibre-style-spec/expressions/)
3601 /// read.
3602 ///
3603 /// See `mln_map_set_global_state_property` in the
3604 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3605 pub fn set_global_state_property(&self, property_name: &str, value: &str) -> Result<()> {
3606 let mut call = self.0.inner.call();
3607 let property_name = call.input(&property_name)?;
3608 let value = call.input(&value)?;
3609 call.discard(|map, completion, out_diagnostic| unsafe {
3610 sys::mln_map_set_global_state_property(
3611 map,
3612 property_name,
3613 value,
3614 completion,
3615 out_diagnostic,
3616 )
3617 })
3618 }
3619
3620 /// Moves the image of an image source.
3621 ///
3622 /// `coordinates` are the image's four corners, clockwise from the top left.
3623 ///
3624 /// See `mln_map_set_image_source_coordinates` in the
3625 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3626 pub fn set_image_source_coordinates(
3627 &self,
3628 source_id: &str,
3629 coordinates: &[LatLng],
3630 ) -> Result<()> {
3631 let mut call = self.0.inner.call();
3632 let coordinate_count = convert::count(coordinates.len())?;
3633 let source_id = call.input(&source_id)?;
3634 let coordinates = call.array(coordinates)?;
3635 call.discard(|map, completion, out_diagnostic| unsafe {
3636 sys::mln_map_set_image_source_coordinates(
3637 map,
3638 source_id,
3639 coordinates,
3640 coordinate_count,
3641 completion,
3642 out_diagnostic,
3643 )
3644 })
3645 }
3646
3647 /// Replaces the image of an image source.
3648 ///
3649 /// See `mln_map_set_image_source_image` in the
3650 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3651 pub fn set_image_source_image(
3652 &self,
3653 source_id: &str,
3654 image: &PremultipliedRgba8Image<'_>,
3655 ) -> Result<()> {
3656 let mut call = self.0.inner.call();
3657 let source_id = call.input(&source_id)?;
3658 let image = call.reference(&image)?;
3659 call.discard(|map, completion, out_diagnostic| unsafe {
3660 sys::mln_map_set_image_source_image(map, source_id, image, completion, out_diagnostic)
3661 })
3662 }
3663
3664 /// Makes an image source load its image from `url`.
3665 ///
3666 /// See `mln_map_set_image_source_url` in the
3667 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3668 pub fn set_image_source_url(&self, source_id: &str, url: &str) -> Result<()> {
3669 let mut call = self.0.inner.call();
3670 let source_id = call.input(&source_id)?;
3671 let url = call.input(&url)?;
3672 call.discard(|map, completion, out_diagnostic| unsafe {
3673 sys::mln_map_set_image_source_url(map, source_id, url, completion, out_diagnostic)
3674 })
3675 }
3676
3677 /// Sets whether the map draws in perspective or axonometric projection, and
3678 /// how much it skews the view.
3679 ///
3680 /// Settings that `options` doesn't set keep their current values.
3681 ///
3682 /// See `mln_map_set_projection_mode` in the
3683 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3684 pub fn set_projection_mode(&self, options: &ProjectionModeOptions) -> Result<()> {
3685 let mut call = self.0.inner.call();
3686 let options = call.reference(&options)?;
3687 call.discard(|map, completion, out_diagnostic| unsafe {
3688 sys::mln_map_set_projection_mode(map, options, completion, out_diagnostic)
3689 })
3690 }
3691
3692 /// Shows or hides an overlay of rendering statistics on the map.
3693 ///
3694 /// See `mln_map_set_rendering_stats_view_enabled` in the
3695 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3696 pub fn set_rendering_stats_view_enabled(&self, enabled: bool) -> Result<()> {
3697 let call = self.0.inner.call();
3698 call.discard(|map, completion, out_diagnostic| unsafe {
3699 sys::mln_map_set_rendering_stats_view_enabled(map, enabled, completion, out_diagnostic)
3700 })
3701 }
3702
3703 /// Adds an image to the map's style, or replaces the image named
3704 /// `image_id`.
3705 ///
3706 /// See `mln_map_set_style_image` in the
3707 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3708 pub fn set_style_image(
3709 &self,
3710 image_id: &str,
3711 image: &PremultipliedRgba8Image<'_>,
3712 options: Option<&StyleImageOptions>,
3713 ) -> Result<()> {
3714 let mut call = self.0.inner.call();
3715 let image_id = call.input(&image_id)?;
3716 let image = call.reference(&image)?;
3717 let options = call.optional_reference(options.as_ref())?;
3718 call.discard(|map, completion, out_diagnostic| unsafe {
3719 sys::mln_map_set_style_image(map, image_id, image, options, completion, out_diagnostic)
3720 })
3721 }
3722
3723 /// Loads the map's style from `json`.
3724 ///
3725 /// The command completes once the style has parsed, and the map's style is
3726 /// then loaded, as `MapHandle::set_style_url()` describes. The style's
3727 /// sources, sprites, and glyphs load in the background.
3728 ///
3729 /// See `mln_map_set_style_json` in the
3730 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3731 pub fn set_style_json(&self, json: &str) -> Result<()> {
3732 let mut call = self.0.inner.call();
3733 let json = call.input(&json)?;
3734 call.discard(|map, completion, out_diagnostic| unsafe {
3735 sys::mln_map_set_style_json(map, json, completion, out_diagnostic)
3736 })
3737 }
3738
3739 /// Sets a property of a layer in the map's style.
3740 ///
3741 /// `property_name` is one of the layer's layout or paint
3742 /// \[properties\](https://maplibre.org/maplibre-style-spec/layers/), or
3743 /// `filter`, `minzoom`, `maxzoom`, `source`, or `source-layer`. A null
3744 /// `value` resets any of these but `source` and `source-layer` to its
3745 /// default.
3746 ///
3747 /// See `mln_map_set_style_layer_property` in the
3748 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3749 pub fn set_style_layer_property(
3750 &self,
3751 layer_id: &str,
3752 property_name: &str,
3753 value: &str,
3754 ) -> Result<()> {
3755 let mut call = self.0.inner.call();
3756 let layer_id = call.input(&layer_id)?;
3757 let property_name = call.input(&property_name)?;
3758 let value = call.input(&value)?;
3759 call.discard(|map, completion, out_diagnostic| unsafe {
3760 sys::mln_map_set_style_layer_property(
3761 map,
3762 layer_id,
3763 property_name,
3764 value,
3765 completion,
3766 out_diagnostic,
3767 )
3768 })
3769 }
3770
3771 /// Replaces the \[light\](https://maplibre.org/maplibre-style-spec/light/)
3772 /// of the map's style.
3773 ///
3774 /// See `mln_map_set_style_light_json` in the
3775 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3776 pub fn set_style_light_json(&self, light_json: &str) -> Result<()> {
3777 let mut call = self.0.inner.call();
3778 let light_json = call.input(&light_json)?;
3779 call.discard(|map, completion, out_diagnostic| unsafe {
3780 sys::mln_map_set_style_light_json(map, light_json, completion, out_diagnostic)
3781 })
3782 }
3783
3784 /// Sets a property of the light of the map's style.
3785 ///
3786 /// See `mln_map_set_style_light_property` in the
3787 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3788 pub fn set_style_light_property(&self, property_name: &str, value: &str) -> Result<()> {
3789 let mut call = self.0.inner.call();
3790 let property_name = call.input(&property_name)?;
3791 let value = call.input(&value)?;
3792 call.discard(|map, completion, out_diagnostic| unsafe {
3793 sys::mln_map_set_style_light_property(
3794 map,
3795 property_name,
3796 value,
3797 completion,
3798 out_diagnostic,
3799 )
3800 })
3801 }
3802
3803 /// Sets whether a source is volatile.
3804 ///
3805 /// The map doesn't store the tiles of a volatile source in the persistent
3806 /// cache.
3807 ///
3808 /// See `mln_map_set_style_source_volatile` in the
3809 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3810 pub fn set_style_source_volatile(&self, source_id: &str, is_volatile: bool) -> Result<()> {
3811 let mut call = self.0.inner.call();
3812 let source_id = call.input(&source_id)?;
3813 call.discard(|map, completion, out_diagnostic| unsafe {
3814 sys::mln_map_set_style_source_volatile(
3815 map,
3816 source_id,
3817 is_volatile,
3818 completion,
3819 out_diagnostic,
3820 )
3821 })
3822 }
3823
3824 /// Sets the default transition of the map's style.
3825 ///
3826 /// See `mln_map_set_style_transition_options` in the
3827 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/style_8h.html).
3828 pub fn set_style_transition_options(&self, options: &StyleTransitionOptions) -> Result<()> {
3829 let mut call = self.0.inner.call();
3830 let options = call.reference(&options)?;
3831 call.discard(|map, completion, out_diagnostic| unsafe {
3832 sys::mln_map_set_style_transition_options(map, options, completion, out_diagnostic)
3833 })
3834 }
3835
3836 /// Loads the map's style from `url`.
3837 ///
3838 /// The command completes once the style document has loaded and parsed. The
3839 /// style's sources, sprites, and glyphs then load in the background.
3840 ///
3841 /// The map's style is loaded from the time a style document parses until
3842 /// the next call to this function. While the style isn't loaded, the
3843 /// commands that change it complete with `Status::InvalidState`. To change
3844 /// a new map's style without a style document, first load an empty style,
3845 /// such as `{"version":8,"sources":{},"layers":[]}`.
3846 ///
3847 /// See `mln_map_set_style_url` in the
3848 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/map_8h.html).
3849 pub fn set_style_url(&self, url: &str) -> Result<()> {
3850 let mut call = self.0.inner.call();
3851 let url = call.input(&url)?;
3852 call.discard(|map, completion, out_diagnostic| unsafe {
3853 sys::mln_map_set_style_url(map, url, completion, out_diagnostic)
3854 })
3855 }
3856
3857 /// Sets how the map chooses which tiles to load, and at what detail.
3858 ///
3859 /// Settings that `options` doesn't set keep their current values.
3860 ///
3861 /// See `mln_map_set_tile_options` in the
3862 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3863 pub fn set_tile_options(&self, options: &MapTileOptions) -> Result<()> {
3864 let mut call = self.0.inner.call();
3865 let options = call.reference(&options)?;
3866 call.discard(|map, completion, out_diagnostic| unsafe {
3867 sys::mln_map_set_tile_options(map, options, completion, out_diagnostic)
3868 })
3869 }
3870
3871 /// Sets how the map orients and constrains its view.
3872 ///
3873 /// Settings that `options` doesn't set keep their current values.
3874 ///
3875 /// See `mln_map_set_viewport_options` in the
3876 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3877 pub fn set_viewport_options(&self, options: &MapViewportOptions) -> Result<()> {
3878 let mut call = self.0.inner.call();
3879 let options = call.reference(&options)?;
3880 call.discard(|map, completion, out_diagnostic| unsafe {
3881 sys::mln_map_set_viewport_options(map, options, completion, out_diagnostic)
3882 })
3883 }
3884
3885 /// Moves the camera, at once or with an animation.
3886 ///
3887 /// Camera fields that `update` doesn't set keep their values, and the
3888 /// update stops any running animation of the fields it sets. The function
3889 /// finishes when the map applies the update, before an animation ends. To
3890 /// learn when an animation ends, set an `CameraTransitionHandler` in its
3891 /// animation options.
3892 ///
3893 /// See `mln_map_update_camera` in the
3894 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
3895 pub fn update_camera(&self, update: &CameraUpdate) -> Result<()> {
3896 let mut call = self.0.inner.call();
3897 let update = call.reference(&update)?;
3898 call.discard(|map, completion, out_diagnostic| unsafe {
3899 sys::mln_map_update_camera(map, update, completion, out_diagnostic)
3900 })
3901 }
3902}