Implement 20x warp speed over water with land prediction and speedometer UI
This commit is contained in:
+21
-7
@@ -54,13 +54,32 @@ app.get('/api/line-of-sight', async (req, res) => {
|
||||
// Generate path points for visualization and spatial query
|
||||
const pathPoints = [];
|
||||
const totalDistance = 20000;
|
||||
const steps = 40;
|
||||
const steps = 80; // More steps for smoother speed transition
|
||||
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const dist = (totalDistance * i) / steps;
|
||||
pathPoints.push(calculateDestination(startLat, startLon, bearing, dist));
|
||||
}
|
||||
|
||||
// Batch check for 'over water' status for all path points
|
||||
// We'll consider a point 'over water' if no city is within 500km
|
||||
const waterChecks = await Promise.all(pathPoints.map(async (p) => {
|
||||
const checkQuery = `
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM cities
|
||||
WHERE ST_DWithin(geom, ST_SetSRID(ST_MakePoint($1, $2), 4326)::geography, 500000)
|
||||
LIMIT 1
|
||||
) as has_land;
|
||||
`;
|
||||
const res = await pool.query(checkQuery, [p.lon, p.lat]);
|
||||
return !res.rows[0].has_land;
|
||||
}));
|
||||
|
||||
const pathPointsWithWater = pathPoints.map((p, i) => ({
|
||||
...p,
|
||||
is_over_water: waterChecks[i]
|
||||
}));
|
||||
|
||||
const lineWKT = `LINESTRING(${pathPoints.map(p => `${p.lon} ${p.lat}`).join(',')})`;
|
||||
|
||||
const query = `
|
||||
@@ -86,11 +105,6 @@ app.get('/api/line-of-sight', async (req, res) => {
|
||||
|
||||
const result = await pool.query(query, [lineWKT, toleranceKm, startLon, startLat]);
|
||||
|
||||
console.log(`Found ${result.rows.length} conurbations near the line.`);
|
||||
if (result.rows.length > 0) {
|
||||
console.log('Sample result row:', result.rows[0]);
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: {
|
||||
@@ -104,7 +118,7 @@ app.get('/api/line-of-sight', async (req, res) => {
|
||||
distance_km: Math.round(row.distance_from_start_km),
|
||||
off_line_km: Math.round(row.distance_off_line_km)
|
||||
})),
|
||||
line_coordinates: pathPoints
|
||||
line_coordinates: pathPointsWithWater
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user