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

@ -7,7 +7,9 @@ import { location } from "$lib/components/lnv/location.svelte";
function getFeatureDistance(f: GeoJSON.Feature, point: [number, number]) {
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") {
// Compute the min distance across all parts
return Math.min(
@ -26,11 +28,15 @@ interface GetFeatureOptions {
}
function getBias() {
if(!location.speed) return 5;
if (!location.speed) return 5;
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 tile = await fetchTile(zxy.z, zxy.x, zxy.y);
const layerData = tile.layers[layer];
@ -41,10 +47,13 @@ export async function getFeature(coord: WorldLocation, layer: string, { lastId,
const feature = layerData.feature(i);
features.push(feature.toGeoJSON(zxy.x, zxy.y, zxy.z));
}
const filtered = features.filter(
(f) =>
f.geometry.type === "LineString" || f.geometry.type == "MultiLineString",
).filter((f) => (filter ? filter(f) : true));
const filtered = features
.filter(
(f) =>
f.geometry.type === "LineString" ||
f.geometry.type == "MultiLineString",
)
.filter((f) => (filter ? filter(f) : true));
if (filtered.length === 0) return null;
const nearest = filtered.reduce((a, b) => {
let distA = getFeatureDistance(a, [coord.lon, coord.lat]);
@ -71,7 +80,11 @@ export async function getFeature(coord: WorldLocation, layer: string, { lastId,
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);
return nearest ? nearest.properties : null;
}