-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
210 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,70 @@ | ||
//use crate::app_state::AppState; | ||
use crate::app_state::AppState; | ||
use crate::core::Connection; | ||
//use crate::data::Database; | ||
//use axum::{ | ||
// extract::{Path, State}, | ||
// http::{header, StatusCode}, | ||
// response::{IntoResponse, Response}, | ||
//}; | ||
use axum::{ | ||
extract::{Path, State}, | ||
http::{header, StatusCode}, | ||
response::{IntoResponse, Response}, | ||
}; | ||
//use martin_tile_utils::TileCoord; | ||
//use std::sync::Arc; | ||
// | ||
//pub async fn tiles<D: Database>( | ||
// Path((z, y, x)): Path<(u32, u32, u32)>, | ||
// State(state): State<Arc<AppState<D>>>, | ||
//) -> Response { | ||
// if let Some(tile_info_source) = state.sources.get("pois") { | ||
// let xyz = TileCoord { | ||
// x, | ||
// y, | ||
// z: z.try_into().unwrap(), | ||
// }; | ||
// match tile_info_source.get_tile(xyz, None).await { | ||
// Ok(tile_data) => ( | ||
// StatusCode::OK, | ||
// [ | ||
// (header::CONTENT_TYPE, "application/vnd.mapbox-vector-tile"), | ||
// (header::ACCESS_CONTROL_ALLOW_ORIGIN, "*"), | ||
// ], | ||
// tile_data, | ||
// ) | ||
// .into_response(), | ||
// Err(_) => (StatusCode::NOT_FOUND, "Tile not found".to_string()).into_response(), | ||
// } | ||
// } else { | ||
// ( | ||
// StatusCode::NOT_FOUND, | ||
// "Tile info source not found".to_string(), | ||
// ) | ||
// .into_response() | ||
// } | ||
//} | ||
use std::sync::Arc; | ||
|
||
pub async fn tiles( | ||
State(state): State<Arc<AppState>>, | ||
Path((workspace_id, connection_id, z, x, y)): Path<(String, String, u32, u32, u32)>, | ||
) -> impl IntoResponse { | ||
let connection = Connection::from_id(&state.app_data, &workspace_id, &connection_id) | ||
.await | ||
.unwrap(); | ||
|
||
let geoconnector = state | ||
.geospatial_config | ||
.get_connection(&connection.id) | ||
.await | ||
.unwrap(); | ||
|
||
let tile = geoconnector.get_tile(z, x, y).await.unwrap(); | ||
|
||
println!("tile"); | ||
println!("{tile:?}"); | ||
|
||
Response::builder() | ||
.status(StatusCode::OK) | ||
.header(header::CONTENT_TYPE, "application/x-protobuf") | ||
.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, "http://localhost:3000") | ||
.header( | ||
header::ACCESS_CONTROL_ALLOW_METHODS, | ||
"GET, POST, PUT, DELETE, OPTIONS", | ||
) | ||
.header(header::ACCESS_CONTROL_ALLOW_HEADERS, "*") | ||
//.header(header::CONTENT_ENCODING, "gzip") | ||
.body(axum::body::Body::from(tile)) | ||
.unwrap() | ||
.into_response() | ||
|
||
//if let Some(tile_info_source) = state.geospatial_config.get("pois") { | ||
// let xyz = TileCoord { | ||
// x, | ||
// y, | ||
// z: z.try_into().unwrap(), | ||
// }; | ||
// match tile_info_source.get_tile(xyz, None).await { | ||
// Ok(tile_data) => ( | ||
// StatusCode::OK, | ||
// [ | ||
// (header::CONTENT_TYPE, "application/vnd.mapbox-vector-tile"), | ||
// (header::ACCESS_CONTROL_ALLOW_ORIGIN, "*"), | ||
// ], | ||
// tile_data, | ||
// ) | ||
// .into_response(), | ||
// Err(_) => (StatusCode::NOT_FOUND, "Tile not found".to_string()).into_response(), | ||
// } | ||
//} else { | ||
// ( | ||
// StatusCode::NOT_FOUND, | ||
// "Tile info source not found".to_string(), | ||
// ) | ||
// .into_response() | ||
//} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters