use axum::{Router, response::IntoResponse, routing::get}; use ecsdb::EntityId; use serde::Deserialize; use serde_json::json; use crate::AppState; use super::HtmxTemplate; pub fn routes() -> axum::Router> { Router::new().route("/", get(map)) } #[derive(Debug, Deserialize)] struct MapArguments { #[serde(default)] geometry: Vec, } async fn map(args: axum_extra::extract::Query) -> impl IntoResponse { let geometry_links = args .geometry .iter() .map(|e| format!("/geometries/{e}/geojson")) .collect::>(); HtmxTemplate { template_name: "map.html", context: json!({ "links": { "geometry":geometry_links } }), } } // #[derive(Deserialize, Default)] // pub struct PopupLocation { // lat: f64, // lon: f64, // } // async fn popup( // db: super::ExtractDatabase, // location: extract::Query, // ) -> impl IntoResponse { // let db = db.acquire().await; // let point = geo::point! {x: location.lon, y: location.lat}; // const FUZZYNESS: f64 = 10.0 * 1000.0; // let fuzzy_rect = { // let min = Geodesic.destination(point, 270.0 + 45.0, FUZZYNESS * f64::sqrt(2.0)); // let max = Geodesic.destination(point, 90.0 + 45.0, FUZZYNESS * f64::sqrt(2.0)); // geo_types::Rect::new(min, max) // }; // let mut neighbours = { // GeoLookupExtension(&db) // .intersecting_rect(&fuzzy_rect) // .filter_map(|e| { // let distance = db // .entity(e) // .component::()? // .min_distance_meters(point); // Some((distance, e)) // }) // .collect::>() // }; // debug!(intersecting = neighbours.len()); // neighbours.sort_by(|a, b| a.0.total_cmp(&b.0)); // neighbours.truncate(5); // let neighbours = neighbours // .into_iter() // .map(|(distance, entity)| { // let entity = db.entity(entity); // let mut context = super::entity_context(entity); // context["distance_meters"] = json!(distance); // context // }) // .collect::>(); // HtmxTemplate { // template_name: "map/popup.html", // context: json!({ // "neighbours": neighbours, // }), // } // }