From 0962c7b3a32dc5867e81bfc9cd4a05105a30e6ff Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Fri, 28 Jun 2024 22:01:35 +0200 Subject: [PATCH 1/7] sources dir --- walkers/src/{sources.rs => sources/mod.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename walkers/src/{sources.rs => sources/mod.rs} (100%) diff --git a/walkers/src/sources.rs b/walkers/src/sources/mod.rs similarity index 100% rename from walkers/src/sources.rs rename to walkers/src/sources/mod.rs From da22acccd67924f1b99a8f26e428e0a200b45b06 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Fri, 28 Jun 2024 22:02:21 +0200 Subject: [PATCH 2/7] compile fix --- walkers/src/sources/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/walkers/src/sources/mod.rs b/walkers/src/sources/mod.rs index 9bcb0a55..2f016fcc 100644 --- a/walkers/src/sources/mod.rs +++ b/walkers/src/sources/mod.rs @@ -131,8 +131,8 @@ impl TileSource for Mapbox { Attribution { text: "© Mapbox, © OpenStreetMap", url: "https://www.mapbox.com/about/maps/", - logo_light: Some(egui::include_image!("../assets/mapbox-logo-white.svg")), - logo_dark: Some(egui::include_image!("../assets/mapbox-logo-black.svg")), + logo_light: Some(egui::include_image!("../../assets/mapbox-logo-white.svg")), + logo_dark: Some(egui::include_image!("../../assets/mapbox-logo-black.svg")), } } From bed3f246bccda8366bf778425e482d04bfd66470 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Fri, 28 Jun 2024 22:05:30 +0200 Subject: [PATCH 3/7] osm mod --- walkers/src/sources/mod.rs | 24 +++--------------------- walkers/src/sources/openstreetmap.rs | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 walkers/src/sources/openstreetmap.rs diff --git a/walkers/src/sources/mod.rs b/walkers/src/sources/mod.rs index 2f016fcc..315c76d3 100644 --- a/walkers/src/sources/mod.rs +++ b/walkers/src/sources/mod.rs @@ -1,6 +1,9 @@ //! Some common HTTP tile sources. Make sure you follow terms of usage of the particular source. +mod openstreetmap; + use crate::mercator::TileId; +pub use openstreetmap::OpenStreetMap; #[derive(Clone)] pub struct Attribution { @@ -20,27 +23,6 @@ pub trait TileSource { } } -/// -pub struct OpenStreetMap; - -impl TileSource for OpenStreetMap { - fn tile_url(&self, tile_id: TileId) -> String { - format!( - "https://tile.openstreetmap.org/{}/{}/{}.png", - tile_id.zoom, tile_id.x, tile_id.y - ) - } - - fn attribution(&self) -> Attribution { - Attribution { - text: "OpenStreetMap contributors", - url: "https://www.openstreetmap.org/copyright", - logo_light: None, - logo_dark: None, - } - } -} - /// Orthophotomap layer from Poland's Geoportal. /// pub struct Geoportal; diff --git a/walkers/src/sources/openstreetmap.rs b/walkers/src/sources/openstreetmap.rs new file mode 100644 index 00000000..e2386e6d --- /dev/null +++ b/walkers/src/sources/openstreetmap.rs @@ -0,0 +1,23 @@ +use super::{Attribution, TileSource}; +use crate::TileId; + +/// +pub struct OpenStreetMap; + +impl TileSource for OpenStreetMap { + fn tile_url(&self, tile_id: TileId) -> String { + format!( + "https://tile.openstreetmap.org/{}/{}/{}.png", + tile_id.zoom, tile_id.x, tile_id.y + ) + } + + fn attribution(&self) -> Attribution { + Attribution { + text: "OpenStreetMap contributors", + url: "https://www.openstreetmap.org/copyright", + logo_light: None, + logo_dark: None, + } + } +} From 7c644fc827745c81168a4df5f757385aca278e27 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Fri, 28 Jun 2024 22:07:32 +0200 Subject: [PATCH 4/7] geoportal --- walkers/src/sources/geoportal.rs | 32 ++++++++++++++++++++++++++++++++ walkers/src/sources/mod.rs | 31 +------------------------------ 2 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 walkers/src/sources/geoportal.rs diff --git a/walkers/src/sources/geoportal.rs b/walkers/src/sources/geoportal.rs new file mode 100644 index 00000000..9d2cc33c --- /dev/null +++ b/walkers/src/sources/geoportal.rs @@ -0,0 +1,32 @@ +use super::{Attribution, TileSource}; +use crate::TileId; + +/// Orthophotomap layer from Poland's Geoportal. +/// +pub struct Geoportal; + +impl TileSource for Geoportal { + fn tile_url(&self, tile_id: TileId) -> String { + format!( + "https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution?\ + &SERVICE=WMTS\ + &REQUEST=GetTile\ + &VERSION=1.0.0\ + &LAYER=ORTOFOTOMAPA\ + &TILEMATRIXSET=EPSG:3857\ + &TILEMATRIX=EPSG:3857:{}\ + &TILEROW={}\ + &TILECOL={}", + tile_id.zoom, tile_id.y, tile_id.x + ) + } + + fn attribution(&self) -> Attribution { + Attribution { + text: "Główny Urząd Geodezji i Kartografii", + url: "https://www.geoportal.gov.pl/", + logo_light: None, + logo_dark: None, + } + } +} diff --git a/walkers/src/sources/mod.rs b/walkers/src/sources/mod.rs index 315c76d3..43581ad8 100644 --- a/walkers/src/sources/mod.rs +++ b/walkers/src/sources/mod.rs @@ -1,6 +1,7 @@ //! Some common HTTP tile sources. Make sure you follow terms of usage of the particular source. mod openstreetmap; +mod geoportal; use crate::mercator::TileId; pub use openstreetmap::OpenStreetMap; @@ -23,36 +24,6 @@ pub trait TileSource { } } -/// Orthophotomap layer from Poland's Geoportal. -/// -pub struct Geoportal; - -impl TileSource for Geoportal { - fn tile_url(&self, tile_id: TileId) -> String { - format!( - "https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution?\ - &SERVICE=WMTS\ - &REQUEST=GetTile\ - &VERSION=1.0.0\ - &LAYER=ORTOFOTOMAPA\ - &TILEMATRIXSET=EPSG:3857\ - &TILEMATRIX=EPSG:3857:{}\ - &TILEROW={}\ - &TILECOL={}", - tile_id.zoom, tile_id.y, tile_id.x - ) - } - - fn attribution(&self) -> Attribution { - Attribution { - text: "Główny Urząd Geodezji i Kartografii", - url: "https://www.geoportal.gov.pl/", - logo_light: None, - logo_dark: None, - } - } -} - /// Predefined Mapbox styles. /// #[derive(Clone, Copy, Default)] From 4d553a2b39d61ad05277926333e4a0a054670592 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Fri, 28 Jun 2024 22:08:47 +0200 Subject: [PATCH 5/7] fix --- walkers/src/sources/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/walkers/src/sources/mod.rs b/walkers/src/sources/mod.rs index 43581ad8..5ab0c9e2 100644 --- a/walkers/src/sources/mod.rs +++ b/walkers/src/sources/mod.rs @@ -1,9 +1,10 @@ //! Some common HTTP tile sources. Make sure you follow terms of usage of the particular source. -mod openstreetmap; mod geoportal; +mod openstreetmap; use crate::mercator::TileId; +pub use geoportal::Geoportal; pub use openstreetmap::OpenStreetMap; #[derive(Clone)] From 6d0232abdb52ad87a1e34e6d2e3752595f2cde1d Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Fri, 28 Jun 2024 22:13:12 +0200 Subject: [PATCH 6/7] mapbox mod --- walkers/src/sources/mapbox.rs | 73 +++++++++++++++++++++++++++++++++++ walkers/src/sources/mod.rs | 72 +--------------------------------- 2 files changed, 75 insertions(+), 70 deletions(-) create mode 100644 walkers/src/sources/mapbox.rs diff --git a/walkers/src/sources/mapbox.rs b/walkers/src/sources/mapbox.rs new file mode 100644 index 00000000..a1738e13 --- /dev/null +++ b/walkers/src/sources/mapbox.rs @@ -0,0 +1,73 @@ +use crate::TileId; + +use super::{Attribution, TileSource}; + +/// Predefined Mapbox styles. +/// +#[derive(Clone, Copy, Default)] +pub enum MapboxStyle { + #[default] + Streets, + Outdoors, + Light, + Dark, + Satellite, + SatelliteStreets, + NavigationDay, + NavigationNight, +} + +impl MapboxStyle { + fn api_slug(&self) -> &'static str { + match self { + Self::Streets => "streets-v12", + Self::Outdoors => "outdoors-v12", + Self::Light => "light-v11", + Self::Dark => "dark-v11", + Self::Satellite => "satellite-v9", + Self::SatelliteStreets => "satellite-streets-v12", + Self::NavigationDay => "navigation-day-v1", + Self::NavigationNight => "navigation-night-v1", + } + } +} + +/// Mapbox static tile source. +/// +#[derive(Default)] +pub struct Mapbox { + /// Predefined style to use + pub style: MapboxStyle, + /// Render tiles at 1024x1024 instead of 512x512 (@2x) + pub high_resolution: bool, + /// Mapbox API key, required + pub access_token: String, +} + +impl TileSource for Mapbox { + fn tile_url(&self, tile_id: TileId) -> String { + format!( + "https://api.mapbox.com/styles/v1/mapbox/{}/tiles/512/{}/{}/{}{}?access_token={}", + self.style.api_slug(), + tile_id.zoom, + tile_id.x, + tile_id.y, + if self.high_resolution { "@2x" } else { "" }, + self.access_token + ) + } + + fn attribution(&self) -> Attribution { + // TODO: Proper linking (https://docs.mapbox.com/help/getting-started/attribution/)) + Attribution { + text: "© Mapbox, © OpenStreetMap", + url: "https://www.mapbox.com/about/maps/", + logo_light: Some(egui::include_image!("../../assets/mapbox-logo-white.svg")), + logo_dark: Some(egui::include_image!("../../assets/mapbox-logo-black.svg")), + } + } + + fn tile_size(&self) -> u32 { + 512 + } +} \ No newline at end of file diff --git a/walkers/src/sources/mod.rs b/walkers/src/sources/mod.rs index 5ab0c9e2..341734d1 100644 --- a/walkers/src/sources/mod.rs +++ b/walkers/src/sources/mod.rs @@ -1,10 +1,12 @@ //! Some common HTTP tile sources. Make sure you follow terms of usage of the particular source. mod geoportal; +mod mapbox; mod openstreetmap; use crate::mercator::TileId; pub use geoportal::Geoportal; +pub use mapbox::{Mapbox, MapboxStyle}; pub use openstreetmap::OpenStreetMap; #[derive(Clone)] @@ -24,73 +26,3 @@ pub trait TileSource { 256 } } - -/// Predefined Mapbox styles. -/// -#[derive(Clone, Copy, Default)] -pub enum MapboxStyle { - #[default] - Streets, - Outdoors, - Light, - Dark, - Satellite, - SatelliteStreets, - NavigationDay, - NavigationNight, -} - -impl MapboxStyle { - fn api_slug(&self) -> &'static str { - match self { - Self::Streets => "streets-v12", - Self::Outdoors => "outdoors-v12", - Self::Light => "light-v11", - Self::Dark => "dark-v11", - Self::Satellite => "satellite-v9", - Self::SatelliteStreets => "satellite-streets-v12", - Self::NavigationDay => "navigation-day-v1", - Self::NavigationNight => "navigation-night-v1", - } - } -} - -/// Mapbox static tile source. -/// -#[derive(Default)] -pub struct Mapbox { - /// Predefined style to use - pub style: MapboxStyle, - /// Render tiles at 1024x1024 instead of 512x512 (@2x) - pub high_resolution: bool, - /// Mapbox API key, required - pub access_token: String, -} - -impl TileSource for Mapbox { - fn tile_url(&self, tile_id: TileId) -> String { - format!( - "https://api.mapbox.com/styles/v1/mapbox/{}/tiles/512/{}/{}/{}{}?access_token={}", - self.style.api_slug(), - tile_id.zoom, - tile_id.x, - tile_id.y, - if self.high_resolution { "@2x" } else { "" }, - self.access_token - ) - } - - fn attribution(&self) -> Attribution { - // TODO: Proper linking (https://docs.mapbox.com/help/getting-started/attribution/)) - Attribution { - text: "© Mapbox, © OpenStreetMap", - url: "https://www.mapbox.com/about/maps/", - logo_light: Some(egui::include_image!("../../assets/mapbox-logo-white.svg")), - logo_dark: Some(egui::include_image!("../../assets/mapbox-logo-black.svg")), - } - } - - fn tile_size(&self) -> u32 { - 512 - } -} From f4b903f6ecf4008792a043d236489bc30bf725b8 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Fri, 28 Jun 2024 22:25:28 +0200 Subject: [PATCH 7/7] fmt --- walkers/src/sources/mapbox.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/walkers/src/sources/mapbox.rs b/walkers/src/sources/mapbox.rs index a1738e13..ee6a9eb7 100644 --- a/walkers/src/sources/mapbox.rs +++ b/walkers/src/sources/mapbox.rs @@ -70,4 +70,4 @@ impl TileSource for Mapbox { fn tile_size(&self) -> u32 { 512 } -} \ No newline at end of file +}