style: run prettier
Some checks failed
TrafficCue CI / check (push) Successful in 1m35s
TrafficCue CI / build-android (push) Has been cancelled
TrafficCue CI / build (push) Has been cancelled

This commit is contained in:
2025-10-25 18:49:52 +02:00
parent 1f99976f97
commit 1035befc6f
2 changed files with 41 additions and 15 deletions

View File

@ -75,7 +75,10 @@ function snapLocation() {
if (!feature) return; if (!feature) return;
if (!rawLocation.current) return; if (!rawLocation.current) return;
if (feature.geometry.type === "LineString") { if (feature.geometry.type === "LineString") {
const loc = nearestPointOnLine(lineString(feature.geometry.coordinates), point([rawLocation.current.lon, rawLocation.current.lat])); const loc = nearestPointOnLine(
lineString(feature.geometry.coordinates),
point([rawLocation.current.lon, rawLocation.current.lat]),
);
snappedLocation.current = { snappedLocation.current = {
lat: loc.geometry.coordinates[1], lat: loc.geometry.coordinates[1],
lon: loc.geometry.coordinates[0], lon: loc.geometry.coordinates[0],
@ -85,7 +88,10 @@ function snapLocation() {
let nearestLoc: GeoJSON.Feature<GeoJSON.Point> | null = null; let nearestLoc: GeoJSON.Feature<GeoJSON.Point> | null = null;
let minDist = Infinity; let minDist = Infinity;
for (const coords of feature.geometry.coordinates) { for (const coords of feature.geometry.coordinates) {
const loc = nearestPointOnLine(lineString(coords), point([rawLocation.current.lon, rawLocation.current.lat])); const loc = nearestPointOnLine(
lineString(coords),
point([rawLocation.current.lon, rawLocation.current.lat]),
);
const dist = Math.hypot( const dist = Math.hypot(
loc.geometry.coordinates[0] - rawLocation.current.lon, loc.geometry.coordinates[0] - rawLocation.current.lon,
loc.geometry.coordinates[1] - rawLocation.current.lat, loc.geometry.coordinates[1] - rawLocation.current.lat,
@ -124,7 +130,14 @@ export function watchLocation() {
location.heading = pos.coords.heading; location.heading = pos.coords.heading;
location.lastUpdate = new Date(); location.lastUpdate = new Date();
const blacklist = ["path", "track", "raceway", "busway", "bus_guideway", "ferry"]; const blacklist = [
"path",
"track",
"raceway",
"busway",
"bus_guideway",
"ferry",
];
getFeature( getFeature(
{ lat: rawLocation.current.lat, lon: rawLocation.current.lon }, { lat: rawLocation.current.lat, lon: rawLocation.current.lon },
"transportation", "transportation",
@ -136,7 +149,7 @@ export function watchLocation() {
return true; return true;
}, },
lastId: lastFeatureId || undefined, lastId: lastFeatureId || undefined,
} },
).then((feature) => { ).then((feature) => {
roadFeature.current = feature; roadFeature.current = feature;
roadMetadata.current = feature ? feature.properties : null; roadMetadata.current = feature ? feature.properties : null;

View File

@ -7,7 +7,9 @@ import { location } from "$lib/components/lnv/location.svelte";
function getFeatureDistance(f: GeoJSON.Feature, point: [number, number]) { function getFeatureDistance(f: GeoJSON.Feature, point: [number, number]) {
if (f.geometry.type === "LineString") { if (f.geometry.type === "LineString") {
return pointToLineDistance(point, lineString(f.geometry.coordinates), { units: "meters" }); return pointToLineDistance(point, lineString(f.geometry.coordinates), {
units: "meters",
});
} else if (f.geometry.type === "MultiLineString") { } else if (f.geometry.type === "MultiLineString") {
// Compute the min distance across all parts // Compute the min distance across all parts
return Math.min( return Math.min(
@ -30,7 +32,11 @@ function getBias() {
return Math.max(5, Math.min(15, location.speed * 0.5)); // Bias increases with speed, min 5, max 15, 0.5 per km/h return Math.max(5, Math.min(15, location.speed * 0.5)); // Bias increases with speed, min 5, max 15, 0.5 per km/h
} }
export async function getFeature(coord: WorldLocation, layer: string, { lastId, filter }: GetFeatureOptions = {}) { export async function getFeature(
coord: WorldLocation,
layer: string,
{ lastId, filter }: GetFeatureOptions = {},
) {
const zxy = coordToTile(coord, 14); const zxy = coordToTile(coord, 14);
const tile = await fetchTile(zxy.z, zxy.x, zxy.y); const tile = await fetchTile(zxy.z, zxy.x, zxy.y);
const layerData = tile.layers[layer]; const layerData = tile.layers[layer];
@ -41,10 +47,13 @@ export async function getFeature(coord: WorldLocation, layer: string, { lastId,
const feature = layerData.feature(i); const feature = layerData.feature(i);
features.push(feature.toGeoJSON(zxy.x, zxy.y, zxy.z)); features.push(feature.toGeoJSON(zxy.x, zxy.y, zxy.z));
} }
const filtered = features.filter( const filtered = features
.filter(
(f) => (f) =>
f.geometry.type === "LineString" || f.geometry.type == "MultiLineString", f.geometry.type === "LineString" ||
).filter((f) => (filter ? filter(f) : true)); f.geometry.type == "MultiLineString",
)
.filter((f) => (filter ? filter(f) : true));
if (filtered.length === 0) return null; if (filtered.length === 0) return null;
const nearest = filtered.reduce((a, b) => { const nearest = filtered.reduce((a, b) => {
let distA = getFeatureDistance(a, [coord.lon, coord.lat]); let distA = getFeatureDistance(a, [coord.lon, coord.lat]);
@ -71,7 +80,11 @@ export async function getFeature(coord: WorldLocation, layer: string, { lastId,
return nearest; return nearest;
} }
export async function getMeta(coord: WorldLocation, layer: string, options?: GetFeatureOptions) { export async function getMeta(
coord: WorldLocation,
layer: string,
options?: GetFeatureOptions,
) {
const nearest = await getFeature(coord, layer, options); const nearest = await getFeature(coord, layer, options);
return nearest ? nearest.properties : null; return nearest ? nearest.properties : null;
} }