diff --git a/data/output/openapi.yaml b/data/output/openapi.yaml index 73c958285..6d5d9d500 100644 --- a/data/output/openapi.yaml +++ b/data/output/openapi.yaml @@ -1339,8 +1339,10 @@ components: type: object properties: name: + description: name of the map type: string - path: + url: + description: where the indoor geojson is located at type: string required: - name diff --git a/server/Cargo.lock b/server/Cargo.lock index 5f31e32c5..e39f83ec6 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1285,16 +1285,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" -[[package]] -name = "earcutr" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79127ed59a85d7687c409e9978547cffb7dc79675355ed22da6b66fd5f6ead01" -dependencies = [ - "itertools 0.11.0", - "num-traits", -] - [[package]] name = "either" version = "1.13.0" @@ -1652,7 +1642,6 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f811f663912a69249fa620dcd2a005db7254529da2d8a0b23942e81f47084501" dependencies = [ - "earcutr", "float_next_after", "geo-types", "geographiclib-rs", @@ -1660,7 +1649,7 @@ dependencies = [ "num-traits", "robust", "rstar", - "spade", + "serde", ] [[package]] @@ -2410,15 +2399,6 @@ dependencies = [ "nom", ] -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.12.1" @@ -5250,18 +5230,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spade" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bd14cf9e23b5241e1b1289ed3b9afc7746c95ead8df52d9254f5ed2d40c561b" -dependencies = [ - "hashbrown 0.14.5", - "num-traits", - "robust", - "smallvec", -] - [[package]] name = "spin" version = "0.9.8" diff --git a/server/Cargo.toml b/server/Cargo.toml index 4df0eff43..b71553a08 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -76,9 +76,9 @@ polars = { version = "0.41.3", features = ["dtype-struct", "parquet"] } #polars = { git = "https://github.com/CommanderStorm/polars.git", branch = "serialisation-experiment", features = ["parquet", "serde", "dtype-full"] } # geodata -geo = "0.28.0" -geozero = { version = "0.13.0", features = ["with-postgis-sqlx", "with-geojson"] } -geo-types = "0.7.13" +geo = { version = "0.28.0", features = ["use-serde"], default-features = false } +geozero = { version = "0.13.0", features = ["with-postgis-sqlx", "with-geojson", "with-wkt", "with-geo", "with-geojson", ], default-features = false } +geo-types = { version = "0.7.13", default-features = false } [dev-dependencies] insta = { version = "1.39.0", features = ["json", "redactions", "yaml"] } diff --git a/server/src/main.rs b/server/src/main.rs index 33286f86f..93490c956 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -198,6 +198,8 @@ async fn run() -> anyhow::Result<()> { .app_data(web::Data::new(data.clone())) .service(health_status_handler) .service(calendar::calendar_handler) + .service(maps::indoor::list_indoor_maps) + .service(maps::indoor::get_indoor_map) .service(search::search_handler) .service(web::scope("/api/feedback").configure(feedback::configure)) .service(web::scope("/api/locations").configure(locations::configure)) diff --git a/server/src/maps/indoor.rs b/server/src/maps/indoor.rs index 055e625b6..a65a7b0f3 100644 --- a/server/src/maps/indoor.rs +++ b/server/src/maps/indoor.rs @@ -1,16 +1,86 @@ +use actix_web::{post, web, HttpResponse}; +use geo_types::Geometry; +use reqwest::Url; +use serde::{Deserialize, Serialize}; use sqlx::{PgPool, Row}; +use tracing::{error, info}; + #[tracing::instrument(skip(pool))] -pub async fn list_indoor_inside_of(pool:&PgPool) ->anyhow::Result>{ - let geom: geo_types::Geometry = geo::Point::new(10.0, 20.0).into(); +pub async fn fetch_indoor_maps_inside_of(pool: &PgPool, geom: Geometry) -> anyhow::Result> { let filtered_groups = sqlx::query("SELECT group_id from indoor_features where ST_Contains(convex_hull::geometry, $1::geometry)") .bind(geozero::wkb::Encode(geom)) .fetch_all(pool) .await?; - let mut filtered_group_ids =Vec::::new(); + let mut filtered_group_ids = Vec::::new(); for group in filtered_groups { let group_id = group.get_unchecked(0); filtered_group_ids.push(group_id); } Ok(filtered_group_ids) -} \ No newline at end of file +} +#[tracing::instrument(skip(pool))] +pub async fn fetch_indoor_map(pool: &PgPool, id: i64) -> anyhow::Result { + let row = sqlx::query("SELECT features from indoor_features where group_id = $1") + .bind(id) + .fetch_one(pool) + .await?; + let value: geozero::wkb::Decode = row.get(0); + + Ok(value.geometry.unwrap()) +} + +#[derive(Deserialize)] +struct Arguments { + bbox: geo::Rect, +} + +#[post("/api/maps/indoor/{id}")] +pub async fn get_indoor_map( + params: web::Path, + data: web::Data, +) -> HttpResponse { + let id = params.into_inner(); + let map=fetch_indoor_map(&data.pool,id).await; + let geometry=match map { + Ok(g) => g, + Err(err) => { + error!("Failed to fetch indoor map {id} because {err:?}"); + return HttpResponse::InternalServerError().finish(); + }, + }; + info!("fetched {geometry:?}"); + HttpResponse::Ok().finish() +} + + +#[derive(Serialize)] +struct RemoteMap{ + name:String, + url:Url, +} + +#[post("/api/maps/indoor")] +pub async fn list_indoor_maps( + web::Query(args): web::Query, + data: web::Data, +) -> HttpResponse { + let maps=fetch_indoor_maps_inside_of(&data.pool,args.bbox.into()).await; + let maps=match maps{ + Ok(m)=>m, + Err(e) => { + error!("could not list maps because {e:?}"); + return HttpResponse::InternalServerError().body("could not get indoor maps, please try again later"); + }, + }; + let mut response = Vec::new(); + for map in maps{ + response.push(RemoteMap{ + name: map.to_string(), + url: format!("https://nav.tum.de/api/maps/indoor/{map}").parse().unwrap(), + }) + } + + HttpResponse::Ok().json(response) +} + diff --git a/server/src/maps/mod.rs b/server/src/maps/mod.rs index 97f661dc9..e64a55df0 100644 --- a/server/src/maps/mod.rs +++ b/server/src/maps/mod.rs @@ -1,4 +1,4 @@ mod fetch_tile; +pub(crate) mod indoor; pub(crate) mod overlay_map; pub(crate) mod overlay_text; -mod indoor;