From 9f98d4cde9a94169c46435119e8f82f5ea0b4d8d Mon Sep 17 00:00:00 2001 From: n4n5 Date: Tue, 2 Jul 2024 20:34:24 +0200 Subject: [PATCH 1/2] add --- walkers/src/extras/images.rs | 3 +++ walkers/src/extras/places.rs | 8 ++++++++ walkers/src/lib.rs | 2 +- walkers/src/map.rs | 8 ++++++++ walkers/src/mercator.rs | 6 ++++++ walkers/src/sources.rs | 20 ++++++++++++++++++++ walkers/src/tiles.rs | 8 ++++++++ walkers/src/zoom.rs | 1 + 8 files changed, 55 insertions(+), 1 deletion(-) diff --git a/walkers/src/extras/images.rs b/walkers/src/extras/images.rs index c3f2a448..dd34432b 100644 --- a/walkers/src/extras/images.rs +++ b/walkers/src/extras/images.rs @@ -14,6 +14,7 @@ pub struct Image { } impl Image { + /// Create a new image. pub fn new(texture: Texture, position: Position) -> Self { Self { position, @@ -34,6 +35,7 @@ impl Image { self.angle = Rot2::from_angle(angle); } + /// Draw the image. pub fn draw(&self, _response: &Response, painter: Painter, projector: &crate::Projector) { let rect = Rect::from_center_size( projector.project(self.position).to_pos2(), @@ -54,6 +56,7 @@ pub struct Images { } impl Images { + /// Create a new [`Images`] plugin. pub fn new(images: Vec) -> Self { Self { images } } diff --git a/walkers/src/extras/places.rs b/walkers/src/extras/places.rs index b7359177..728c72d4 100644 --- a/walkers/src/extras/places.rs +++ b/walkers/src/extras/places.rs @@ -5,12 +5,19 @@ use crate::{Plugin, Position}; /// Visual style of the place. #[derive(Clone)] pub struct Style { + /// Font used for the label. pub label_font: FontId, + /// Color of the label. pub label_color: Color32, + /// Background color of the label. pub label_background: Color32, + /// Font used for the symbol. pub symbol_font: FontId, + /// Color of the symbol. pub symbol_color: Color32, + /// Background color of the symbol. pub symbol_background: Color32, + /// Stroke of the symbol. pub symbol_stroke: Stroke, } @@ -96,6 +103,7 @@ pub struct Places { } impl Places { + /// Create a new [`Places`] plugin. pub fn new(places: Vec) -> Self { Self { places } } diff --git a/walkers/src/lib.rs b/walkers/src/lib.rs index 88d1c7fa..33409655 100644 --- a/walkers/src/lib.rs +++ b/walkers/src/lib.rs @@ -1,5 +1,5 @@ #![doc = include_str!("../README.md")] -#![deny(clippy::unwrap_used, rustdoc::broken_intra_doc_links)] +#![deny(missing_docs, clippy::unwrap_used, rustdoc::broken_intra_doc_links)] mod center; mod download; diff --git a/walkers/src/map.rs b/walkers/src/map.rs index c5666c29..2687f5ac 100644 --- a/walkers/src/map.rs +++ b/walkers/src/map.rs @@ -44,6 +44,7 @@ pub struct Map<'a, 'b, 'c> { } impl<'a, 'b, 'c> Map<'a, 'b, 'c> { + /// Create a new map widget. pub fn new( tiles: Option<&'b mut dyn TilesManager>, memory: &'a mut MapMemory, @@ -65,6 +66,12 @@ impl<'a, 'b, 'c> Map<'a, 'b, 'c> { self } + /// Set tiles manager to be used by the map. + pub fn with_tiles_manager(mut self, tiles: &'b mut dyn TilesManager) -> Self { + self.tiles = Some(tiles); + self + } + /// Set whether map should perform zoom gesture. /// /// Zoom is typically triggered by the mouse wheel while holding ctrl key on native @@ -90,6 +97,7 @@ pub struct Projector { } impl Projector { + /// Create a new projector. pub fn new(clip_rect: Rect, map_memory: &MapMemory, my_position: Position) -> Self { Self { clip_rect, diff --git a/walkers/src/mercator.rs b/walkers/src/mercator.rs index 20c81759..986d1df8 100644 --- a/walkers/src/mercator.rs +++ b/walkers/src/mercator.rs @@ -25,10 +25,12 @@ impl Position { Self(geo_types::Point::new(lon, lat)) } + /// Latitude pub fn lat(&self) -> f64 { self.0.y() } + /// Longitude pub fn lon(&self) -> f64 { self.0.x() } @@ -126,6 +128,7 @@ impl TileId { Pixels::new(self.x as f64 * tile_size, self.y as f64 * tile_size) } + /// Move to east pub fn east(&self) -> Option { Some(TileId { x: self.x + 1, @@ -134,6 +137,7 @@ impl TileId { }) } + /// Move to west pub fn west(&self) -> Option { Some(TileId { x: self.x.checked_sub(1)?, @@ -142,6 +146,7 @@ impl TileId { }) } + /// Move to north pub fn north(&self) -> Option { Some(TileId { x: self.x, @@ -150,6 +155,7 @@ impl TileId { }) } + /// Move to south pub fn south(&self) -> Option { Some(TileId { x: self.x, diff --git a/walkers/src/sources.rs b/walkers/src/sources.rs index 9bcb0a55..d4b6eaa5 100644 --- a/walkers/src/sources.rs +++ b/walkers/src/sources.rs @@ -2,16 +2,28 @@ use crate::mercator::TileId; +/// Attribution information for a tile source. #[derive(Clone)] pub struct Attribution { + /// Text to display pub text: &'static str, + + /// URL to open when the text is clicked pub url: &'static str, + + /// Light logo to display pub logo_light: Option>, + + /// Dark logo to display pub logo_dark: Option>, } +/// Common tile source interface. pub trait TileSource { + /// URL of the tile image. fn tile_url(&self, tile_id: TileId) -> String; + + /// Attribution information. fn attribution(&self) -> Attribution; /// Size of each tile, should be a multiple of 256 @@ -75,14 +87,22 @@ impl TileSource for Geoportal { /// #[derive(Clone, Copy, Default)] pub enum MapboxStyle { + /// Mapbox Streets style #[default] Streets, + /// Mapbox Outdoors style Outdoors, + /// Mapbox Light style Light, + /// Mapbox Dark style Dark, + /// Mapbox Satellite style Satellite, + /// Mapbox Satellite Streets style SatelliteStreets, + /// Mapbox Navigation Day style NavigationDay, + /// Mapbox Navigation Night style NavigationNight, } diff --git a/walkers/src/tiles.rs b/walkers/src/tiles.rs index 639fa312..db1e1d14 100644 --- a/walkers/src/tiles.rs +++ b/walkers/src/tiles.rs @@ -12,10 +12,12 @@ pub(crate) fn rect(screen_position: Vec2, tile_size: f64) -> Rect { Rect::from_min_size(screen_position.to_pos2(), Vec2::splat(tile_size as f32)) } +/// Texture handle with a size. #[derive(Clone)] pub struct Texture(TextureHandle); impl Texture { + /// Load the texture from the image bytes. pub fn new(image: &[u8], ctx: &Context) -> Result { let image = image::load_from_memory(image)?.to_rgba8(); let pixels = image.as_flat_samples(); @@ -51,9 +53,15 @@ impl Texture { } } +/// Manages the tiles cache and downloads the missing ones. pub trait TilesManager { + /// Get the tile at the given `TileId` fn at(&mut self, tile_id: TileId) -> Option; + + /// Attribution of the source this tile cache pulls images from fn attribution(&self) -> Attribution; + + /// Size of each tile fn tile_size(&self) -> u32; } diff --git a/walkers/src/zoom.rs b/walkers/src/zoom.rs index a591fa24..867b3832 100644 --- a/walkers/src/zoom.rs +++ b/walkers/src/zoom.rs @@ -1,3 +1,4 @@ +/// Invalid Zoom. #[derive(thiserror::Error, Debug, PartialEq, Eq)] #[error("invalid zoom level")] pub struct InvalidZoom; From a1057ed593e5f4a8822d16b7f6bcdaa61fd00945 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Sat, 6 Jul 2024 20:58:20 +0200 Subject: [PATCH 2/2] update --- walkers/src/map.rs | 2 +- walkers/src/sources/mapbox.rs | 8 ++++++++ walkers/src/sources/mod.rs | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/walkers/src/map.rs b/walkers/src/map.rs index 2124ba73..1d265d4a 100644 --- a/walkers/src/map.rs +++ b/walkers/src/map.rs @@ -67,7 +67,7 @@ impl<'a, 'b, 'c> Map<'a, 'b, 'c> { } /// Set tiles manager to be used by the map. - pub fn with_tiles_manager(mut self, tiles: &'b mut dyn TilesManager) -> Self { + pub fn with_tiles_manager(mut self, tiles: &'b mut dyn Tiles) -> Self { self.tiles = Some(tiles); self } diff --git a/walkers/src/sources/mapbox.rs b/walkers/src/sources/mapbox.rs index ee6a9eb7..5f135fd7 100644 --- a/walkers/src/sources/mapbox.rs +++ b/walkers/src/sources/mapbox.rs @@ -6,14 +6,22 @@ use super::{Attribution, TileSource}; /// #[derive(Clone, Copy, Default)] pub enum MapboxStyle { + /// Streets Style (default) #[default] Streets, + /// Outdoors Style Outdoors, + /// Light Style Light, + /// Dark Style Dark, + /// Satellite Style Satellite, + /// Satellite Streets Style SatelliteStreets, + /// Navigation Day Style NavigationDay, + /// Navigation Night Style NavigationNight, } diff --git a/walkers/src/sources/mod.rs b/walkers/src/sources/mod.rs index c0e5f6c6..76a3cf2e 100644 --- a/walkers/src/sources/mod.rs +++ b/walkers/src/sources/mod.rs @@ -10,16 +10,23 @@ pub use mapbox::{Mapbox, MapboxStyle}; pub use openstreetmap::OpenStreetMap; #[derive(Clone)] +/// Attribution information for the tile source. pub struct Attribution { + /// Attribution text. pub text: &'static str, + /// URL to the attribution source. pub url: &'static str, + /// Logo for the attribution. pub logo_light: Option>, + /// Dark version of the logo. pub logo_dark: Option>, } /// Remote tile server definition, source for the [`crate::HttpTiles`]. pub trait TileSource { + /// URL for the tile with the given id. fn tile_url(&self, tile_id: TileId) -> String; + /// Attribution information for the tile source. fn attribution(&self) -> Attribution; /// Size of each tile, should be a multiple of 256.