Skip to content

Commit 93d6959

Browse files
committed
add commandline args to parse multiple tiles
1 parent b9280eb commit 93d6959

5 files changed

Lines changed: 157 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ name = "sailor"
2525
path = "src/bin/main.rs"
2626

2727
[dependencies]
28+
clap = { version = "4", features = ["derive"] }
2829
config = "0.14"
2930
crossbeam-channel = "0.5"
3031
log = { version = "0.4", features = ["serde"] }

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ cargo build --verbose --bin sailor
1616

1717
```
1818
cargo build --verbose --bin sailor --no-default-features --features metal
19-
```
19+
```
20+
21+
### Debug the Zurich Landesmuseeum tile
22+
23+
```
24+
cargo run --release -- -t 14/8580/5737
25+
```
26+
27+
Use any number of `-t` args to load multiple tiles. If no args are passed, load a full map.

src/bin/app_state.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ impl AppState {
6565
self.feature_collection.clone()
6666
}
6767

68-
pub fn css_cache_mut(&mut self) -> &mut RulesCache {
69-
&mut self.css_cache
70-
}
71-
7268
pub fn load_tile(&mut self, tile_id: TileId) {
7369
self.tile_cache.finalize_loaded_tiles();
7470
if !self.visible_tiles.contains(&tile_id) {

src/bin/main.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod stats;
66
use std::sync::Arc;
77

88
use crate::config::CONFIG;
9+
use clap::Parser;
910
use lyon::math::vector;
1011
use osm::math::{deg2num, tile_to_world_space, TileId};
1112
use winit::{
@@ -21,6 +22,8 @@ fn main() {
2122
log::set_max_level(CONFIG.general.log.level.to_level_filter());
2223
pretty_env_logger::init();
2324

25+
let args = Args::parse();
26+
2427
let tile_coordinate = deg2num(
2528
CONFIG.map.initial.center.latitude,
2629
CONFIG.map.initial.center.longitude,
@@ -72,6 +75,7 @@ fn main() {
7275
modifiers_state,
7376
mouse_down,
7477
last_pos,
78+
args,
7579
};
7680

7781
// Hack to make the UI scale correctly.
@@ -93,6 +97,7 @@ pub struct Application {
9397
modifiers_state: ModifiersState,
9498
mouse_down: bool,
9599
last_pos: LogicalPosition<f64>,
100+
args: Args,
96101
}
97102

98103
impl ApplicationHandler for Application {
@@ -211,9 +216,22 @@ impl ApplicationHandler for Application {
211216
if !event_loop.exiting() {
212217
self.painter.update_shader();
213218
// self.app_state.load_tile(TileId::new(13, 4290, 2868));
214-
self.app_state.load_tile(TileId::new(14, 8580, 5737));
215-
// self.app_state.load_tile(TileId::new(17, 137290, 91796));
216-
// self.app_state.load_tiles();
219+
220+
if self.args.tile.is_empty() {
221+
self.app_state.load_tiles();
222+
} else {
223+
for tile in &self.args.tile {
224+
let coords: Vec<u32> =
225+
tile.split("/").filter_map(|v| v.parse().ok()).collect();
226+
if coords.len() != 3 {
227+
continue;
228+
}
229+
230+
self.app_state
231+
.load_tile(TileId::new(coords[0], coords[1], coords[2]));
232+
}
233+
}
234+
217235
self.painter.paint(&mut self.hud, &mut self.app_state);
218236

219237
self.app_state.stats.capture_frame();
@@ -231,3 +249,14 @@ impl ApplicationHandler for Application {
231249
self.painter.window.request_redraw();
232250
}
233251
}
252+
253+
/// Render a map beautifully and ultra fast with CSS styling
254+
#[derive(Parser, Debug)]
255+
#[command(version, about, long_about = None)]
256+
struct Args {
257+
/// Tile to load (this argument can be given multiple times to load multiple tiles)
258+
///
259+
/// If no tiles were given the full map is loaded.
260+
#[arg(short, long)]
261+
tile: Vec<String>,
262+
}

0 commit comments

Comments
 (0)