this repo has no description
1use axum::{Router, response::IntoResponse, routing::get};
2use ecsdb::EntityId;
3use serde::Deserialize;
4use serde_json::json;
5
6use crate::AppState;
7
8use super::HtmxTemplate;
9
10pub fn routes() -> axum::Router<AppState<'static>> {
11 Router::new().route("/", get(map))
12}
13
14#[derive(Debug, Deserialize)]
15struct MapArguments {
16 #[serde(default)]
17 geometry: Vec<EntityId>,
18}
19
20async fn map(args: axum_extra::extract::Query<MapArguments>) -> impl IntoResponse {
21 let geometry_links = args
22 .geometry
23 .iter()
24 .map(|e| format!("/geometries/{e}/geojson"))
25 .collect::<Vec<_>>();
26
27 HtmxTemplate {
28 template_name: "map.html",
29 context: json!({
30 "links": {
31 "geometry":geometry_links
32 }
33 }),
34 }
35}
36
37// #[derive(Deserialize, Default)]
38// pub struct PopupLocation {
39// lat: f64,
40// lon: f64,
41// }
42
43// async fn popup(
44// db: super::ExtractDatabase,
45// location: extract::Query<PopupLocation>,
46// ) -> impl IntoResponse {
47// let db = db.acquire().await;
48
49// let point = geo::point! {x: location.lon, y: location.lat};
50
51// const FUZZYNESS: f64 = 10.0 * 1000.0;
52// let fuzzy_rect = {
53// let min = Geodesic.destination(point, 270.0 + 45.0, FUZZYNESS * f64::sqrt(2.0));
54// let max = Geodesic.destination(point, 90.0 + 45.0, FUZZYNESS * f64::sqrt(2.0));
55// geo_types::Rect::new(min, max)
56// };
57
58// let mut neighbours = {
59// GeoLookupExtension(&db)
60// .intersecting_rect(&fuzzy_rect)
61// .filter_map(|e| {
62// let distance = db
63// .entity(e)
64// .component::<Geometry>()?
65// .min_distance_meters(point);
66// Some((distance, e))
67// })
68// .collect::<Vec<_>>()
69// };
70
71// debug!(intersecting = neighbours.len());
72
73// neighbours.sort_by(|a, b| a.0.total_cmp(&b.0));
74// neighbours.truncate(5);
75
76// let neighbours = neighbours
77// .into_iter()
78// .map(|(distance, entity)| {
79// let entity = db.entity(entity);
80// let mut context = super::entity_context(entity);
81// context["distance_meters"] = json!(distance);
82// context
83// })
84// .collect::<Vec<_>>();
85
86// HtmxTemplate {
87// template_name: "map/popup.html",
88// context: json!({
89// "neighbours": neighbours,
90// }),
91// }
92// }