main
parent 4bcac75aa2
commit dce1929167

@ -1 +1,2 @@
DATABASE_URL=D:/Share/Map/MBTiles/中国4-10层卫星地图(G).mbtiles TILE_BASE_PATH=D:/Share/Map/MBTiles/中国4-10层卫星地图(G).mbtiles
TERRAIN_BASE_PATH=D:/Share/Map/terrain

55
Cargo.lock generated

@ -34,6 +34,29 @@ dependencies = [
"smallvec", "smallvec",
] ]
[[package]]
name = "actix-files"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf0bdd6ff79de7c9a021f5d9ea79ce23e108d8bfc9b49b5b4a2cf6fad5a35212"
dependencies = [
"actix-http",
"actix-service",
"actix-utils",
"actix-web",
"bitflags 2.5.0",
"bytes",
"derive_more",
"futures-core",
"http-range",
"log",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite",
"v_htmlescape",
]
[[package]] [[package]]
name = "actix-http" name = "actix-http"
version = "3.6.0" version = "3.6.0"
@ -673,6 +696,12 @@ dependencies = [
"itoa", "itoa",
] ]
[[package]]
name = "http-range"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.8.0" version = "1.8.0"
@ -787,6 +816,7 @@ name = "mbtiles_server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-cors", "actix-cors",
"actix-files",
"actix-web", "actix-web",
"dotenvy", "dotenvy",
"env_logger", "env_logger",
@ -808,6 +838,16 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.2" version = "0.7.2"
@ -1292,6 +1332,15 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicase"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.15" version = "0.3.15"
@ -1340,6 +1389,12 @@ dependencies = [
"rand", "rand",
] ]
[[package]]
name = "v_htmlescape"
version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e8257fbc510f0a46eb602c10215901938b5c2a7d5e70fc11483b1d3c9b5b18c"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"

@ -3,8 +3,16 @@ name = "mbtiles_server"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
# [target.x86_64-unknown-linux-musl]
# linker = "rust-lld"
# rustflags = ["-C", "linker-flavor=ld.lld"]
[dependencies] [dependencies]
actix-cors = "0.7.0" actix-cors = "0.7.0"
actix-files = "0.6.5"
actix-web = "4.5.1" actix-web = "4.5.1"
dotenvy = "0.15.7" dotenvy = "0.15.7"
env_logger = "0.11.3" env_logger = "0.11.3"

@ -1,3 +1,11 @@
# 地图瓦片服务 # 地图瓦片服务
mbtiles 发布服务 mbtiles 发布服务
## 使用
```
TILE_BASE_PATH=mbtiles瓦片文件路径
TERRAIN_BASE_PATH=terrain文件存储路径
```

@ -2,7 +2,7 @@ type Pool = ::r2d2::Pool<::r2d2_sqlite::SqliteConnectionManager>;
pub type Connection = ::r2d2::PooledConnection<::r2d2_sqlite::SqliteConnectionManager>; pub type Connection = ::r2d2::PooledConnection<::r2d2_sqlite::SqliteConnectionManager>;
fn initialize_db_pool() -> Pool { fn initialize_db_pool() -> Pool {
let conn_spec = std::env::var("DATABASE_URL").expect("DATABASE_URL should be set"); let conn_spec = std::env::var("TILE_BASE_PATH").expect("TILE_BASE_PATH should be set");
let manager = ::r2d2_sqlite::SqliteConnectionManager::file(conn_spec); let manager = ::r2d2_sqlite::SqliteConnectionManager::file(conn_spec);
Pool::new(manager).unwrap() Pool::new(manager).unwrap()
} }
@ -43,7 +43,7 @@ async fn execute(
Ok(data) Ok(data)
} }
#[::actix_web::get("/{z}/{x}/{y}.png")] #[::actix_web::get("/tile/{z}/{x}/{y}.png")]
async fn get_tile( async fn get_tile(
pool: ::actix_web::web::Data<Pool>, pool: ::actix_web::web::Data<Pool>,
info: ::actix_web::web::Path<(u32, i64, i64)>, info: ::actix_web::web::Path<(u32, i64, i64)>,
@ -68,6 +68,16 @@ async fn get_tile(
.body(data) .body(data)
} }
#[::actix_web::get("/terrain/{tail:.*}")]
async fn get_terrain(
terrain: ::actix_web::web::Data<String>,
info: ::actix_web::web::Path<String>,
) -> impl ::actix_web::Responder {
let info = info.into_inner();
::log::info!("{}", terrain.to_string() + &info);
::actix_files::NamedFile::open(terrain.to_string() + &info)
}
#[::actix_web::main] #[::actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
::dotenvy::dotenv().ok(); ::dotenvy::dotenv().ok();
@ -76,6 +86,12 @@ async fn main() -> std::io::Result<()> {
let pool = initialize_db_pool(); let pool = initialize_db_pool();
let mut terrain = std::env::var("TERRAIN_BASE_PATH").expect("TERRAIN_BASE_PATH should be set");
if !terrain.ends_with("/") {
terrain.push('/');
}
::log::info!("starting HTTP server at http://127.0.0.1:8080"); ::log::info!("starting HTTP server at http://127.0.0.1:8080");
::actix_web::HttpServer::new(move || { ::actix_web::HttpServer::new(move || {
@ -96,7 +112,9 @@ async fn main() -> std::io::Result<()> {
.max_age(3600), .max_age(3600),
) )
.app_data(::actix_web::web::Data::new(pool.clone())) .app_data(::actix_web::web::Data::new(pool.clone()))
.app_data(::actix_web::web::Data::new(terrain.clone()))
.service(get_tile) .service(get_tile)
.service(get_terrain)
}) })
.bind(("127.0.0.1", 8080))? .bind(("127.0.0.1", 8080))?
.workers(2) .workers(2)

Loading…
Cancel
Save