1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use crate::coords::WorldTileCoords;
use crate::error::Error;
use crate::style::source::TileAddressingScheme;
use async_trait::async_trait;
pub type HTTPClientFactory<HC> = dyn Fn() -> HC;
#[cfg_attr(feature = "no-thread-safe-futures", async_trait(?Send))]
#[cfg_attr(not(feature = "no-thread-safe-futures"), async_trait)]
pub trait HttpClient: Clone + Sync + Send + 'static {
async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error>;
}
#[derive(Clone)]
pub struct HttpSourceClient<HC>
where
HC: HttpClient,
{
inner_client: HC,
}
#[derive(Clone)]
pub enum SourceClient<HC>
where
HC: HttpClient,
{
Http(HttpSourceClient<HC>),
Mbtiles {
},
}
impl<HC> SourceClient<HC>
where
HC: HttpClient,
{
pub async fn fetch(&self, coords: &WorldTileCoords) -> Result<Vec<u8>, Error> {
match self {
SourceClient::Http(client) => client.fetch(coords).await,
SourceClient::Mbtiles { .. } => unimplemented!(),
}
}
}
impl<HC> HttpSourceClient<HC>
where
HC: HttpClient,
{
pub fn new(http_client: HC) -> Self {
Self {
inner_client: http_client,
}
}
pub async fn fetch(&self, coords: &WorldTileCoords) -> Result<Vec<u8>, Error> {
let tile_coords = coords.into_tile(TileAddressingScheme::TMS).unwrap();
self.inner_client
.fetch(
format!(
"https://maps.tuerantuer.org/europe_germany/{z}/{x}/{y}.pbf",
x = tile_coords.x,
y = tile_coords.y,
z = tile_coords.z
)
.as_str(),
)
.await
}
}