Skip to content

Commit

Permalink
Add PostGIS tile source
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Aug 8, 2023
1 parent 0d15634 commit a65ffbe
Show file tree
Hide file tree
Showing 16 changed files with 1,425 additions and 65 deletions.
125 changes: 118 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sqlx = { version = "0.7.0", default-features = false, features = [ "runtime-toki
thiserror = "1.0.31"
tokio = { version = "1.19.2" }

#[patch.crates-io]
[patch.crates-io]
#tile-grid = { path = "../tile-grid" }
#geozero = { path = "../geozero/geozero" }
#fast_paths = { path = "../fast_paths" }
11 changes: 11 additions & 0 deletions bbox-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ pub fn from_config_or_exit<'a, T: Default + Deserialize<'a>>(tag: &str) -> T {
}
}

pub fn from_config_root_or_exit<'a, T: Default + Deserialize<'a>>() -> T {
let config = app_config();
match config.extract() {
Ok(config) => config,
Err(err) => {
config_error_exit(err);
Default::default()
}
}
}

pub fn from_config_opt_or_exit<'a, T: Deserialize<'a>>(tag: &str) -> Option<T> {
let config = app_config();
config
Expand Down
6 changes: 5 additions & 1 deletion bbox-tile-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ crossbeam = "0.8.1"
dyn-clone = "1.0.6"
futures = "0.3"
futures-util = "0.3.21"
#geozero = { workspace = true, features = [ "with-mvt", "with-postgis-sqlx" ] }
geozero = { git = "https://github.com/georust/geozero", branch = "mvttrans", features = [ "with-mvt", "with-postgis-sqlx" ] }
indicatif = "0.16.2"
log = { workspace = true }
martin-mbtiles = { version = "0.4.0", default-features = false, features = ["rustls"] }
Expand All @@ -39,9 +41,11 @@ rusoto_core = { version = "0.47.0", default-features = false, features = ["rustl
rusoto_s3 = { version = "0.47.0", default-features = false, features = ["rustls"] }
serde = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
tempfile = "3.3.0"
thiserror = { workspace = true }
tile-grid = "0.5.2"
#tile-grid = "0.5.2"
tile-grid = { git = "https://github.com/pka/tile-grid" }
tilejson = "0.3.2"
tokio = { version = "1.17.0", features = ["rt-multi-thread", "fs", "sync"] }

Expand Down
7 changes: 6 additions & 1 deletion bbox-tile-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ Map viewer examples:

Map viewer template examples:

x-www-browser http://localhost:8080/html/maplibre/mbtiles_mvt_fl
x-www-browser http://localhost:8080/html/maplibre-asset-style/mbtiles_mvt_fl

With PG Service:

curl -s http://localhost:8080/xyz/ne_10m_populated_places.style.json | jq .
x-www-browser http://localhost:8080/html/maplibre/ne_10m_populated_places


Relase Build:
Expand Down
19 changes: 10 additions & 9 deletions bbox-tile-server/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cache::{
files::FileCache, s3::S3Cache, s3putfiles, BoxRead, CacheLayout, TileCacheType, TileWriter,
};
use crate::service::TileService;
use crate::service::{ServiceError, TileService};
use bbox_core::config::error_exit;
use clap::{Args, Parser};
use indicatif::{ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -168,8 +168,11 @@ impl TileService {
let task_queue_size = writer_task_count + threads * 2;
let mut tasks = Vec::with_capacity(task_queue_size);

let tileset = self.tileset(&args.tileset).unwrap();
let source = self.source(&args.tileset).unwrap();
let tileset = self
.tileset(&args.tileset)
.ok_or(ServiceError::TilesetNotFound(args.tileset.clone()))?;
let source = &tileset.source;
let suffix = tileset.tile_suffix().to_string();
let tms = self.grid(&tileset.tms)?;
let bbox = if let Some(numlist) = &args.extent {
let arr: Vec<f64> = numlist
Expand All @@ -187,7 +190,7 @@ impl TileService {
tms.xy_bbox()
};

info!("Tile source {source:?}");
debug!("Tile source {source:?}");
let file_dir = args
.base_dir
.as_ref()
Expand Down Expand Up @@ -222,19 +225,17 @@ impl TileService {
let griditer = tms.xyz_iterator(&bbox, minzoom, maxzoom);
info!("Seeding tiles from level {minzoom} to {maxzoom}");
for tile in griditer {
let path = CacheLayout::Zxy.path_string(&PathBuf::new(), &tile, "png");
let path = CacheLayout::Zxy.path_string(&PathBuf::new(), &tile, &suffix);
progress.set_message(path.clone());
progress.inc(1);
// TODO: we should not clone for each tile, only for a pool of tasks
let service = self.clone();
let tileset = args.tileset.clone();
let file_writer = file_writer.clone();
let suffix = suffix.clone();
let tx = tx.clone();
tasks.push(task::spawn(async move {
let tile = service
.read_tile(&tileset, "WebMercatorQuad", &tile, "png")
.await
.unwrap();
let tile = service.read_tile(&tileset, &tile, &suffix).await.unwrap();
let input: BoxRead = Box::new(tile.body);

file_writer.put_tile(path.clone(), input).await.unwrap();
Expand Down
Loading

0 comments on commit a65ffbe

Please sign in to comment.