This commit is contained in:
Dongho Kim
2025-11-28 23:25:17 +09:00
parent 8e889aa992
commit afdcf23222
6 changed files with 259 additions and 28 deletions

107
frontend/index.html Normal file
View File

@@ -0,0 +1,107 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Maps</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #1a1a1a;
font-family: system-ui, -apple-system, sans-serif;
}
canvas {
width: 100vw;
height: 100vh;
display: block;
}
#ui-container {
position: absolute;
top: 20px;
right: 20px;
display: flex;
flex-direction: column;
gap: 10px;
background: rgba(0, 0, 0, 0.5);
padding: 10px;
border-radius: 8px;
backdrop-filter: blur(5px);
color: white;
}
.control-group {
display: flex;
flex-direction: column;
gap: 5px;
}
button {
background: #333;
color: white;
border: 1px solid #555;
padding: 8px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background: #444;
}
button:active {
background: #222;
}
#debug-info {
position: absolute;
bottom: 20px;
left: 20px;
color: rgba(255, 255, 255, 0.7);
font-size: 12px;
pointer-events: none;
background: rgba(0, 0, 0, 0.5);
padding: 5px 10px;
border-radius: 4px;
}
</style>
</head>
<body>
<div id="ui-container">
<div class="control-group">
<button id="btn-zoom-in">+</button>
<button id="btn-zoom-out">-</button>
</div>
<div class="control-group">
<label for="zoom-slider" style="font-size: 12px;">Zoom</label>
<input type="range" id="zoom-slider" min="0" max="100" value="50">
</div>
<button id="btn-location">📍 My Location</button>
</div>
<div id="debug-info">
Zoom: <span id="debug-zoom">--</span> | Pos: <span id="debug-pos">--</span>
</div>
<script type="module">
import init from './wasm.js';
async function run() {
try {
await init();
console.log("WASM initialized");
} catch (e) {
console.error("Failed to initialize WASM:", e);
}
}
run();
</script>
</body>
</html>

View File

@@ -192,7 +192,7 @@ fn create_road_mesh(points: &[[f64; 2]], width: f32) -> Vec<Vertex> {
async fn fetch_cached(url: &str) -> Option<String> {
let window = web_sys::window()?;
let caches = window.caches().ok()?;
let cache_name = "map-data-v1";
let cache_name = "map-data-v2";
let cache = wasm_bindgen_futures::JsFuture::from(caches.open(cache_name)).await.ok()?;
let cache: web_sys::Cache = cache.dyn_into().ok()?;
@@ -839,7 +839,7 @@ pub async fn run() {
let window_clone_for_fetch = window.clone();
wasm_bindgen_futures::spawn_local(async move {
// Fetch nodes
let url_nodes = format!("http://localhost:3000/api/tiles/{}/{}/{}", z, x, y);
let url_nodes = format!("/api/tiles/{}/{}/{}", z, x, y);
let nodes_data = if let Some(json) = fetch_cached(&url_nodes).await {
serde_json::from_str::<Vec<MapNode>>(&json).ok()
} else {
@@ -847,7 +847,7 @@ pub async fn run() {
};
// Fetch ways
let url_ways = format!("http://localhost:3000/api/tiles/{}/{}/{}/ways", z, x, y);
let url_ways = format!("/api/tiles/{}/{}/{}/ways", z, x, y);
let ways_data = if let Some(json) = fetch_cached(&url_ways).await {
serde_json::from_str::<Vec<MapWay>>(&json).ok()
} else {
@@ -855,7 +855,7 @@ pub async fn run() {
};
// Fetch buildings
let url_buildings = format!("http://localhost:3000/api/tiles/{}/{}/{}/buildings", z, x, y);
let url_buildings = format!("/api/tiles/{}/{}/{}/buildings", z, x, y);
let buildings_data = if let Some(json) = fetch_cached(&url_buildings).await {
serde_json::from_str::<Vec<MapWay>>(&json).ok()
} else {
@@ -863,7 +863,7 @@ pub async fn run() {
};
// Fetch landuse
let url_landuse = format!("http://localhost:3000/api/tiles/{}/{}/{}/landuse", z, x, y);
let url_landuse = format!("/api/tiles/{}/{}/{}/landuse", z, x, y);
let landuse_data = if let Some(json) = fetch_cached(&url_landuse).await {
serde_json::from_str::<Vec<MapWay>>(&json).ok()
} else {
@@ -871,7 +871,7 @@ pub async fn run() {
};
// Fetch water
let url_water = format!("http://localhost:3000/api/tiles/{}/{}/{}/water", z, x, y);
let url_water = format!("/api/tiles/{}/{}/{}/water", z, x, y);
let water_data = if let Some(json) = fetch_cached(&url_water).await {
serde_json::from_str::<Vec<MapWay>>(&json).ok()
} else {
@@ -879,7 +879,7 @@ pub async fn run() {
};
// Fetch railways
let url_railways = format!("http://localhost:3000/api/tiles/{}/{}/{}/railways", z, x, y);
let url_railways = format!("/api/tiles/{}/{}/{}/railways", z, x, y);
let railways_data = if let Some(json) = fetch_cached(&url_railways).await {
serde_json::from_str::<Vec<MapWay>>(&json).ok()
} else {
@@ -1099,6 +1099,10 @@ fn create_pipeline(
let x = world_pos.x * camera.params.x + camera.params.z;
let y = world_pos.y * camera.params.y + camera.params.w;
// Globe Effect: Spherize
// let r2 = x*x + y*y;
// let w = 1.0 + r2 * 0.5;
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
return out;
}
@@ -1184,6 +1188,10 @@ fn create_road_pipeline(
let x = world_pos.x * camera.params.x + camera.params.z;
let y = world_pos.y * camera.params.y + camera.params.w;
// Globe Effect: Spherize
// let r2 = x*x + y*y;
// let w = 1.0 + r2 * 0.5;
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
return out;
}
@@ -1268,6 +1276,10 @@ fn create_building_pipeline(
let x = world_pos.x * camera.params.x + camera.params.z;
let y = world_pos.y * camera.params.y + camera.params.w;
// Globe Effect: Spherize
// let r2 = x*x + y*y;
// let w = 1.0 + r2 * 0.5;
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
return out;
}
@@ -1352,6 +1364,10 @@ fn create_landuse_pipeline(
let x = world_pos.x * camera.params.x + camera.params.z;
let y = world_pos.y * camera.params.y + camera.params.w;
// Globe Effect: Spherize
// let r2 = x*x + y*y;
// let w = 1.0 + r2 * 0.5;
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
return out;
}
@@ -1446,6 +1462,10 @@ fn create_water_pipeline(
let x = world_pos.x * camera.params.x + camera.params.z;
let y = world_pos.y * camera.params.y + camera.params.w;
// Globe Effect: Spherize
// let r2 = x*x + y*y;
// let w = 1.0 + r2 * 0.5;
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
return out;
}
@@ -1540,6 +1560,10 @@ fn create_railway_pipeline(
let x = world_pos.x * camera.params.x + camera.params.z;
let y = world_pos.y * camera.params.y + camera.params.w;
// Globe Effect: Spherize
// let r2 = x*x + y*y;
// let w = 1.0 + r2 * 0.5;
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
return out;
}