feat(hazards): snap to road
Some checks failed
TrafficCue Server CI / check (push) Failing after 53s
TrafficCue Server CD / build (push) Successful in 1m47s

This commit is contained in:
2025-10-03 18:12:56 +02:00
parent 94b4de4920
commit 3de797ec1b

View File

@ -422,9 +422,32 @@ if (process.env.HAZARDS_ENABLED) {
const nlat = Number(parseFloat(lat).toFixed(4));
const nlon = Number(parseFloat(lon).toFixed(4));
const mapMatched = await fetch((process.env.VALHALLA || "https://valhalla1.openstreetmap.de") + "/locate", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
locations: [
{
lat: nlat,
lon: nlon,
}
]
})
}).then(res => res.json()).catch(() => null);
let mmlat = nlat;
let mmlon = nlon;
if(mapMatched && Array.isArray(mapMatched) && mapMatched[0] && mapMatched[0].edges && mapMatched[0].edges[0]) {
mmlat = mapMatched[0].edges[0].correlated_lat;
mmlon = mapMatched[0].edges[0].correlated_lon;
}
const hazard = new Hazard();
hazard.latitude = nlat;
hazard.longitude = nlon;
hazard.latitude = mmlat;
hazard.longitude = mmlon;
hazard.type = type;
hazard.votes = 1;
hazard.user = user;