# ViewState in maplibre::render::view_state - Rust
API documentation for the Rust `ViewState` struct in crate `maplibre`.

# Struct maplibre::render::view_state::ViewState

source ·

    pub struct ViewState {
        zoom: ChangeObserver<Zoom>,
        camera: ChangeObserver<Camera>,
        perspective: Perspective,
        width: f64,
        height: f64,
        edge_insets: EdgeInsets,
    }

## Fields§

§ `zoom: ChangeObserver<Zoom>` § `camera: ChangeObserver<Camera>` § `perspective: Perspective` § `width: f64` § `height: f64` § `edge_insets: EdgeInsets`

## Implementations§

source §

### impl ViewState

source

#### pub fn new<F: Into<Rad<f64>>, P: Into<Deg<f64>>>( window_size: PhysicalSize, position: WorldCoords, zoom: Zoom, pitch: P, fovy: F ) -> Self

source

#### pub fn set_edge_insets(&mut self, edge_insets: EdgeInsets)

source

#### pub fn edge_insets(&self) -> &EdgeInsets

source

#### pub fn resize(&mut self, size: LogicalSize)

source

#### pub fn create_view_region(&self, visible_level: ZoomLevel) -> Option<ViewRegion>

source

#### pub fn get_intersection_time( ray_origin: Vector3<f64>, ray_direction: Vector3<f64>, plane_origin: Vector3<f64>, plane_normal: Vector3<f64> ) -> f64

source

#### pub fn furthest_distance( &self, camera_height: f64, center_offset: Point2<f64> ) -> f64

source

#### pub fn camera_to_center_distance(&self) -> f64

source

#### pub fn view_projection(&self) -> ViewProjection

This function matches how maplibre-gl-js implements perspective and cameras at the time of the mapbox -> maplibre fork: src/geo/transform.ts#L680

source

#### pub fn zoom(&self) -> Zoom

source

#### pub fn did_zoom_change(&self) -> bool

source

#### pub fn update_zoom(&mut self, new_zoom: Zoom)

source

#### pub fn camera(&self) -> &Camera

source

#### pub fn camera_mut(&mut self) -> &mut Camera

source

#### pub fn did_camera_change(&self) -> bool

source

#### pub fn update_references(&mut self)

source

#### fn clip_to_window_transform(&self) -> Matrix4<f64>

A transform which can be used to transform between clip and window space. Adopted from here (Direct3D).

source

#### fn clip_to_window(&self, clip: &Vector4<f64>) -> Vector4<f64>

Transforms coordinates in clip space to window coordinates.

Adopted from here (Direct3D).

source

#### fn clip_to_window_vulkan(&self, clip: &Vector4<f64>) -> Vector3<f64>

Alternative implementation to `clip_to_window`. Transforms coordinates in clip space to window coordinates.

Adopted from here and here (Vulkan).

source

#### fn window_to_world( &self, window: &Vector3<f64>, inverted_view_proj: &InvertedViewProjection ) -> Vector3<f64>

Order of transformations reversed: https://computergraphics.stackexchange.com/questions/6087/screen-space-coordinates-to-eye-space-conversion/6093 `w` is lost.

OpenGL explanation: https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space#From_window_to_ndc

source

#### fn window_to_world_nalgebra( window: &Vector3<f64>, inverted_view_proj: &InvertedViewProjection, width: f64, height: f64 ) -> Vector3<f64>

Alternative implementation to `window_to_world`

Adopted from here.

source

#### pub fn window_to_world_at_ground( &self, window: &Vector2<f64>, inverted_view_proj: &InvertedViewProjection, bound: bool ) -> Option<Vector2<f64>>

Gets the world coordinates for the specified `window` coordinates on the `z=0` plane.

source

#### pub fn view_region_bounding_box( &self, inverted_view_proj: &InvertedViewProjection ) -> Option<Aabb2<f64>>

Calculates an `Aabb2` bounding box which contains at least the visible area on the `z=0` plane. One can think of it as being the bounding box of the geometry which forms the intersection between the viewing frustum and the `z=0` plane.

This implementation works in the world 3D space. It casts rays from the corners of the window to calculate intersections points with the `z=0` plane. Then a bounding box is calculated.

Note: It is possible that no such bounding box exists. This is the case if the `z=0` plane is not in view.

source

#### pub fn view_region_bounding_box_ndc(&self) -> Option<Aabb2<f64>>

An alternative implementation for `view_bounding_box`.

This implementation works in the NDC space. We are creating a plane in the world 3D space. Then we are transforming it to the NDC space. In NDC space it is easy to calculate the intersection points between an Aabb3 and a plane. The resulting Aabb2 is returned.

## Auto Trait Implementations§

§

### impl RefUnwindSafe for ViewState

§

### impl Send for ViewState

§

### impl Sync for ViewState

§

### impl Unpin for ViewState

§

### impl UnwindSafe for ViewState

## Blanket Implementations§

source §

### impl<T> Any for T
where T: 'static + ?Sized,

source §

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
source §

### impl<T> Borrow<T> for T
where T: ?Sized,

source §

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source §

### impl<T> BorrowMut<T> for T
where T: ?Sized,

source §

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

### impl<T> Downcast<T> for T

§

#### fn downcast(&self) -> &T

§

### impl<T> Downcast for T
where T: Any,

§

#### fn into_any(self: Box<T>) -> Box<dyn Any>

Convert `Box<dyn Trait>` (where `Trait: Downcast`) to `Box<dyn Any>`. `Box<dyn Any>` can then be further `downcast` into `Box<ConcreteType>` where `ConcreteType` implements `Trait`.
§

#### fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert `Rc<Trait>` (where `Trait: Downcast`) to `Rc<Any>`. `Rc<Any>` can then be further `downcast` into `Rc<ConcreteType>` where `ConcreteType` implements `Trait`.
§

#### fn as_any(&self) -> &(dyn Any + 'static)

Convert `&Trait` (where `Trait: Downcast`) to `&Any`. This is needed since Rust cannot generate `&Any`’s vtable from `&Trait`’s.
§

#### fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert `&mut Trait` (where `Trait: Downcast`) to `&Any`. This is needed since Rust cannot generate `&mut Any`’s vtable from `&mut Trait`’s.
§

### impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

#### fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert `Arc<Trait>` (where `Trait: Downcast`) to `Arc<Any>`. `Arc<Any>` can then be further `downcast` into `Arc<ConcreteType>` where `ConcreteType` implements `Trait`.
source §

### impl<T> From<T> for T

source §

#### fn from(t: T) -> T

Returns the argument unchanged.

§

### impl<T> Instrument for T

§

#### fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [`Span`], returning an `Instrumented` wrapper. Read more
§

#### fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more
source §

### impl<T, U> Into<U> for T
where U: From<T>,

source §

#### fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

source §

### impl<T> Same for T

§

#### type Output = T

Should always be `Self`
source §

### impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

#### type Error = Infallible

The type returned in the event of a conversion error.
source §

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source §

### impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source §

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

### impl<T> Upcast<T> for T

§

#### fn upcast(&self) -> Option<&T>

§

### impl<T> WithSubscriber for T

§

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a [`WithDispatch`] wrapper. Read more
§

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a [`WithDispatch`] wrapper. Read more
§

### impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

#### fn is_within(&self, b: &G2) -> bool

source §

### impl<T> Resource for T
where T: 'static,

§

### impl<T> WasmNotSend for T
where T: Send,

§

### impl<T> WasmNotSync for T
where T: Sync,