Skip to main content

Basemap

Struct Basemap 

Source
pub struct Basemap { /* private fields */ }
Expand description

A map view: one style, or several stacked bottom to top, a size in CSS pixels, a centre and MapLibre zoom (512 px tiles, fractional allowed), and a device pixel ratio (images are pixel_ratio times larger with the same view and label layout).

Implementations§

Source§

impl Basemap

Source

pub fn new(style: impl Into<String>) -> Self

A view of one style (a URL or style JSON, e.g. from crate::providers): 800 x 600 CSS pixels at zoom 0.

Source

pub fn stack(styles: Vec<String>) -> Self

A view of several styles drawn bottom to top (e.g. a basemap published as separate hillshade, base and label services).

Source

pub fn size(self, width: u32, height: u32) -> Self

View size in CSS pixels.

Source

pub fn center(self, longitude: f64, latitude: f64) -> Self

View centre as (longitude, latitude).

Source

pub fn zoom(self, zoom: f64) -> Self

MapLibre zoom (0-22, fractional allowed).

Source

pub fn bounds(self, bounds: [f64; 4], crs: Crs) -> Result<Self, BasemapError>

Fit bounds ([xmin, ymin, xmax, ymax] in crs) instead of a centre and zoom. Apply after size.

Source

pub fn pixel_ratio(self, pixel_ratio: f64) -> Self

Device pixels per CSS pixel (MapLibre’s devicePixelRatio).

Source

pub fn layers(self, layers: Vec<String>) -> Self

Layer filter applied to every style: plain IDs keep only those layers, --prefixed IDs drop them.

Source

pub fn labels(self, labels: Labels) -> Self

Labels to keep in every style: all, none, or only the labels.

Source

pub fn features(self, features: Vec<String>) -> Self

Feature filter applied to every style: plain names keep those features ("water", "roads", …), --prefixed names drop them.

Source

pub fn auth_token(self, token: impl Into<String>) -> Self

Access token for the tile service.

Source

pub fn tile_timeout_ms(self, ms: u32) -> Self

Per-tile HTTP timeout in milliseconds.

Source

pub fn max_tiles(self, n: u32) -> Self

Maximum tiles fetched per style.

Source

pub fn tile_concurrency(self, n: u32) -> Self

Parallel tile downloads.

Source

pub fn fail_on_tile_error(self, fail: bool) -> Self

Abort on a failed tile instead of leaving it empty.

Source

pub fn set_view( &mut self, center: Option<(f64, f64)>, zoom: Option<f64>, ) -> Result<&mut Self, BasemapError>

Set the centre and/or zoom (None keeps the current value).

Source

pub fn set_bounds( &mut self, bounds: [f64; 4], crs: Crs, ) -> Result<&mut Self, BasemapError>

Fit the view to bounds in crs, keeping its size.

Source

pub fn get_bounds(&self, lonlat: bool) -> [f64; 4]

The view’s [xmin, ymin, xmax, ymax]: EPSG:3857 metres, or degrees with lonlat.

Source

pub fn get_center(&self) -> (f64, f64)

The view centre as (longitude, latitude).

Source

pub fn get_zoom(&self) -> f64

The view’s MapLibre zoom.

Source

pub fn get_size(&self) -> (u32, u32)

Size of rendered images in device pixels (width, height times pixel_ratio).

Source

pub fn get_attribution(&self) -> Result<String, BasemapError>

The attribution text the view’s styles ask maps to show (see crate::attribution()).

Source

pub fn render_array(&self) -> Result<RenderResult, BasemapError>

Render to straight-alpha RGBA pixels (device pixels).

Source

pub fn render_png(&self, path: Option<&Path>) -> Result<Vec<u8>, BasemapError>

Render a PNG, written to path when given; returns its bytes.

Source

pub fn render_svg( &self, path: Option<&Path>, options: &SvgOptions, ) -> Result<String, BasemapError>

Render a vector SVG (width x height user units; pixel_ratio does not apply), written to path when given; returns the document.

Trait Implementations§

Source§

impl Clone for Basemap

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Basemap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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> 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