Skip to content

Commit

Permalink
test local layer
Browse files Browse the repository at this point in the history
  • Loading branch information
zerj9 committed Dec 28, 2024
1 parent 9bb0e64 commit e5eeb75
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 19 deletions.
38 changes: 20 additions & 18 deletions gridwalk-backend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ use axum::{
routing::{delete, get, post},
Router,
};
use http::{header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE}, HeaderName};
use http::Method;
use http::{
header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
HeaderName,
};
use std::sync::Arc;
use tower_cookies::CookieManagerLayer;
use tower_http::{
Expand All @@ -34,22 +37,22 @@ fn create_dynamic_cors() -> CorsLayer {
.allow_credentials(true)
.allow_methods([Method::GET, Method::OPTIONS, Method::POST])
.allow_headers([
AUTHORIZATION,
ACCEPT,
AUTHORIZATION,
ACCEPT,
CONTENT_TYPE,
HeaderName::from_static("x-file-type"),
HeaderName::from_static("x-workspace-id"),
HeaderName::from_static("x-chunk-number"),
HeaderName::from_static("x-total-chunks"),
HeaderName::from_static("x-file-size"),
])
.expose_headers([
HeaderName::from_static("x-file-type"),
HeaderName::from_static("x-workspace-id"),
HeaderName::from_static("x-chunk-number"),
HeaderName::from_static("x-total-chunks"),
HeaderName::from_static("x-file-size")
])
HeaderName::from_static("x-file-type"),
HeaderName::from_static("x-workspace-id"),
HeaderName::from_static("x-chunk-number"),
HeaderName::from_static("x-total-chunks"),
HeaderName::from_static("x-file-size"),
])
.expose_headers([
HeaderName::from_static("x-file-type"),
HeaderName::from_static("x-workspace-id"),
HeaderName::from_static("x-chunk-number"),
HeaderName::from_static("x-total-chunks"),
HeaderName::from_static("x-file-size"),
])
.allow_origin(origins)
}

Expand All @@ -61,12 +64,11 @@ pub fn create_app(app_state: AppState) -> Router {

let shared_state = Arc::new(app_state);


let upload_router = Router::new()
.route("/upload_layer", post(upload_layer))
.layer(DefaultBodyLimit::disable())
.layer(RequestBodyLimitLayer::new(100 * 1024 * 1024))
.layer(create_dynamic_cors())
.layer(create_dynamic_cors())
.layer(middleware::from_fn_with_state(
shared_state.clone(),
auth_middleware,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ export const useMapInit = (config: MapConfig): UseMapInitResult => {
"Content-Type": "application/json",
},
};
} else if (url.includes("http://localhost:3001")) {
return {
url: url,
headers: {
'Accept': 'application/x-protobuf'
},
credentials: 'include'
};
} else if (url.startsWith(window.location.origin)) {
return {
url: url,
Expand All @@ -117,7 +125,33 @@ export const useMapInit = (config: MapConfig): UseMapInitResult => {

mapInstance.on("load", () => {
console.log("Map loaded successfully");
});

// Configure the map with vector tiles
mapInstance.addSource("local-tiles", {
type: "vector",
tiles: [
"http://localhost:3001/workspaces/f57e7ba0-a30f-47bd-b641-11d5e25b9978/connections/primary/sources/london/tiles/{z}/{x}/{y}"
],
minzoom: 0,
maxzoom: 14,
});


// Add a layer for each vector tile layer you want to display
// You'll need to know the source layer names from your vector tiles
mapInstance.addLayer({
id: "local-tile-layer",
type: "fill", // or "line", "symbol", etc. depending on your data
source: "local-tiles",
"source-layer": "london", // Replace with actual source layer name
paint: {
"fill-color": "#888888",
"fill-opacity": 0.8
}
});


});
} catch (error) {
console.error("Error initializing map:", error);
setMapError(
Expand Down

0 comments on commit e5eeb75

Please sign in to comment.