feat(hazards): snap to road
This commit is contained in:
27
src/main.ts
27
src/main.ts
@ -422,9 +422,32 @@ if (process.env.HAZARDS_ENABLED) {
|
|||||||
const nlat = Number(parseFloat(lat).toFixed(4));
|
const nlat = Number(parseFloat(lat).toFixed(4));
|
||||||
const nlon = Number(parseFloat(lon).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();
|
const hazard = new Hazard();
|
||||||
hazard.latitude = nlat;
|
hazard.latitude = mmlat;
|
||||||
hazard.longitude = nlon;
|
hazard.longitude = mmlon;
|
||||||
hazard.type = type;
|
hazard.type = type;
|
||||||
hazard.votes = 1;
|
hazard.votes = 1;
|
||||||
hazard.user = user;
|
hazard.user = user;
|
||||||
|
|||||||
Reference in New Issue
Block a user