From c344c581b7509eb8c5036559290d50132bca8ce9 Mon Sep 17 00:00:00 2001 From: Cfp Date: Fri, 27 Jun 2025 14:31:48 +0200 Subject: [PATCH] feat: improve voice guidance --- src/lib/services/navigation/VoiceGuidance.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib/services/navigation/VoiceGuidance.ts b/src/lib/services/navigation/VoiceGuidance.ts index e1e1542..e01113d 100644 --- a/src/lib/services/navigation/VoiceGuidance.ts +++ b/src/lib/services/navigation/VoiceGuidance.ts @@ -2,12 +2,20 @@ import { OVERPASS_SERVER } from "../hosts"; import type { OverpassResult } from "../Overpass"; export async function generateVoiceGuidance(maneuver: Maneuver, shape: WorldLocation[]): Promise { + if(maneuver.begin_shape_index == 0) { + return maneuver.verbal_pre_transition_instruction; + } + + if(maneuver.type === 26 || maneuver.type === 27) { + return `Im Kreisverkehr die ${maneuver.roundabout_exit_count}te Ausfahrt nehmen${(maneuver.street_names ?? []).length == 0 ? "." : ` auf ${(maneuver.street_names || []).join(", ")}.`}`; + } + const landmarks = await findNearbyLandmarks(shape[maneuver.begin_shape_index]); if(landmarks.length == 0) { return maneuver.verbal_pre_transition_instruction; } console.log("Original instruction:", maneuver.verbal_pre_transition_instruction); - return `Hinter ${landmarks[0].tags.name}, ${typeToName(maneuver.type)} auf ${(maneuver.street_names || []).join(", ")}.`; + return `Hinter ${landmarks[0].tags.name}, ${typeToName(maneuver.type)}${(maneuver.street_names ?? []).length == 0 ? "." : ` auf ${(maneuver.street_names || []).join(", ")}.`}`; } function typeToName(type: number) { @@ -47,9 +55,9 @@ function typeToName(type: number) { return "Links halten"; case 25: return "Einordnen"; - case 26: - case 27: - return "Kreisverkehr"; + // case 26: + // case 27: + // return "Kreisverkehr"; case 37: return "Rechts einordnen"; case 38: @@ -67,6 +75,8 @@ export async function findNearbyLandmarks(location: WorldLocation) { method: "POST", body: `[out:json]; ( + node(around:${radius}, ${lat}, ${lon})["amenity"="fuel"]["name"]; + way(around:${radius}, ${lat}, ${lon})["amenity"="fuel"]["name"]; node(around:${radius}, ${lat}, ${lon})["tourism"="artwork"]["name"]; way(around:${radius}, ${lat}, ${lon})["tourism"="artwork"]["name"]; node(around:${radius}, ${lat}, ${lon})["shop"]["name"];