Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sources module #169

Merged
merged 7 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 0 additions & 142 deletions walkers/src/sources.rs

This file was deleted.

32 changes: 32 additions & 0 deletions walkers/src/sources/geoportal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use super::{Attribution, TileSource};
use crate::TileId;

/// Orthophotomap layer from Poland's Geoportal.
/// <https://www.geoportal.gov.pl/uslugi/usluga-przegladania-wms>
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,
}
}
}
73 changes: 73 additions & 0 deletions walkers/src/sources/mapbox.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use crate::TileId;

use super::{Attribution, TileSource};

/// Predefined Mapbox styles.
/// <https://docs.mapbox.com/api/maps/styles/#classic-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.
/// <https://docs.mapbox.com/api/maps/static-tiles/>
#[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
}
}
28 changes: 28 additions & 0 deletions walkers/src/sources/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! 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)]
pub struct Attribution {
pub text: &'static str,
pub url: &'static str,
pub logo_light: Option<egui::ImageSource<'static>>,
pub logo_dark: Option<egui::ImageSource<'static>>,
}

pub trait TileSource {
fn tile_url(&self, tile_id: TileId) -> String;
fn attribution(&self) -> Attribution;

/// Size of each tile, should be a multiple of 256
fn tile_size(&self) -> u32 {
256
}
}
23 changes: 23 additions & 0 deletions walkers/src/sources/openstreetmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::{Attribution, TileSource};
use crate::TileId;

/// <https://www.openstreetmap.org/about>
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,
}
}
}
Loading