feat(routing): use road max speed for verbal pre instruction distance
This commit is contained in:
@ -6,6 +6,7 @@ import type { LngLatBoundsLike } from "maplibre-gl";
|
|||||||
import { generateVoiceGuidance } from "./VoiceGuidance";
|
import { generateVoiceGuidance } from "./VoiceGuidance";
|
||||||
import { keepScreenOn } from "tauri-plugin-keep-screen-on-api";
|
import { keepScreenOn } from "tauri-plugin-keep-screen-on-api";
|
||||||
import { m } from "$lang/messages";
|
import { m } from "$lang/messages";
|
||||||
|
import { getFeature, getSpeed } from "../TileMeta";
|
||||||
|
|
||||||
export const routing = $state({
|
export const routing = $state({
|
||||||
geojson: {
|
geojson: {
|
||||||
@ -150,6 +151,28 @@ export async function startRoute(trip: Trip) {
|
|||||||
let hasAnnouncedPreInstruction = false;
|
let hasAnnouncedPreInstruction = false;
|
||||||
const USE_LANDMARK_INSTRUCTIONS = false;
|
const USE_LANDMARK_INSTRUCTIONS = false;
|
||||||
|
|
||||||
|
let maneuverSpeed = { idx: -1, speed: 50 };
|
||||||
|
|
||||||
|
async function getSpeedForManeuver(idx: number) {
|
||||||
|
if (maneuverSpeed.idx === idx) {
|
||||||
|
return maneuverSpeed.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!routing.currentTrip) return 50;
|
||||||
|
|
||||||
|
const esi = routing.currentTrip!.legs[0].maneuvers[idx].end_shape_index;
|
||||||
|
const shape = routing.currentTrip!.legs[0].shape;
|
||||||
|
const polyline = decodePolyline(shape);
|
||||||
|
const point = polyline[esi];
|
||||||
|
|
||||||
|
const feature = await getFeature(point, "transportation");
|
||||||
|
if (!feature || !feature.properties) return 50;
|
||||||
|
|
||||||
|
const speed = getSpeed(feature.properties.maxspeed || "50") || 50;
|
||||||
|
maneuverSpeed = { idx, speed };
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
async function tickRoute() {
|
async function tickRoute() {
|
||||||
const trip = routing.currentTrip;
|
const trip = routing.currentTrip;
|
||||||
const info = routing.currentTripInfo;
|
const info = routing.currentTripInfo;
|
||||||
@ -201,7 +224,7 @@ async function tickRoute() {
|
|||||||
// console.log("Distance to end of current maneuver: ", distanceToEnd, " meters");
|
// console.log("Distance to end of current maneuver: ", distanceToEnd, " meters");
|
||||||
// console.log("Speed: ", location.speed, " km/h");
|
// console.log("Speed: ", location.speed, " km/h");
|
||||||
const verbalDistance = verbalPreInstructionDistance(
|
const verbalDistance = verbalPreInstructionDistance(
|
||||||
location.speed || 50, // Assuming location has a speed property
|
await getSpeedForManeuver(routing.currentTripInfo.maneuverIdx),
|
||||||
);
|
);
|
||||||
if (distanceToEnd <= verbalDistance) {
|
if (distanceToEnd <= verbalDistance) {
|
||||||
hasAnnouncedPreInstruction = true;
|
hasAnnouncedPreInstruction = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user