diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-03-11 19:57:18 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-03-11 19:57:18 +0100 |
commit | fd4f3318db8df3e9f0542535fb7df6d621d07768 (patch) | |
tree | a7266db8f159d3cd7a487bc7eb80f3fcb2dd807d /src/renderer | |
parent | 4e8ce5bbaf5aa71f7e00e7a131fc6b25e623c992 (diff) | |
download | hittekaart-fd4f3318db8df3e9f0542535fb7df6d621d07768.tar.gz hittekaart-fd4f3318db8df3e9f0542535fb7df6d621d07768.tar.bz2 hittekaart-fd4f3318db8df3e9f0542535fb7df6d621d07768.zip |
first implementation of tile hunter mode
This is a very basic idea, the downside is that you basically cannot
"fix" the tilehunt overlay to a specific zoom level. It might be nice to
get a second renderer that renders the tile hunt for a fixed zoom, and
then adjusts the output tiles accordingly (then it also takes more space
again though).
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/mod.rs | 1 | ||||
-rw-r--r-- | src/renderer/tile-marked.png | bin | 0 -> 116 bytes | |||
-rw-r--r-- | src/renderer/tilehunt.rs | 52 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 927c6ed..f109872 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -7,6 +7,7 @@ use crossbeam_channel::Sender; use super::gpx::Coordinates; pub mod heatmap; +pub mod tilehunt; const CHANNEL_SIZE: usize = 30; diff --git a/src/renderer/tile-marked.png b/src/renderer/tile-marked.png Binary files differnew file mode 100644 index 0000000..0b05ce2 --- /dev/null +++ b/src/renderer/tile-marked.png diff --git a/src/renderer/tilehunt.rs b/src/renderer/tilehunt.rs new file mode 100644 index 0000000..f44644b --- /dev/null +++ b/src/renderer/tilehunt.rs @@ -0,0 +1,52 @@ +//! Actual rendering functions for tile hunts. +use color_eyre::eyre::Result; +use crossbeam_channel::Sender; +use fnv::FnvHashSet; + +use super::{ + super::{ + gpx::Coordinates, + layer::{TILE_HEIGHT, TILE_WIDTH}, + }, + RenderedTile, +}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct Renderer; + +impl super::Renderer for Renderer { + type Prepared = FnvHashSet<(u64, u64)>; + + fn prepare(zoom: u32, tracks: &[Vec<Coordinates>], tick: Sender<()>) -> Result<Self::Prepared> { + let mut marked = FnvHashSet::default(); + + for track in tracks { + for point in track { + let merc = point.web_mercator(zoom); + let tile_x = merc.0 / TILE_WIDTH; + let tile_y = merc.1 / TILE_HEIGHT; + marked.insert((tile_x, tile_y)); + } + + tick.send(()).unwrap(); + } + + Ok(marked) + } + + fn colorize(layer: Self::Prepared, tx: Sender<RenderedTile>) -> Result<()> { + static IMAGE_DATA: &[u8] = include_bytes!("tile-marked.png"); + for (tile_x, tile_y) in layer { + tx.send(RenderedTile { + x: tile_x, + y: tile_y, + data: IMAGE_DATA.to_vec(), + })?; + } + Ok(()) + } + + fn tile_count(layer: &Self::Prepared) -> Result<u64> { + Ok(layer.len().try_into().unwrap()) + } +} |