style: run prettier
All checks were successful
TrafficCue CI / check (push) Successful in 1m34s
TrafficCue CI / build (push) Successful in 10m30s
TrafficCue CI / build-android (push) Successful in 26m47s

This commit is contained in:
2025-10-21 15:46:50 +02:00
parent 4036790a4b
commit 372b31876d
17 changed files with 306 additions and 167 deletions

View File

@ -11,8 +11,8 @@ function getFeatureDistance(f: GeoJSON.Feature, point: [number, number]) {
// Compute the min distance across all parts
return Math.min(
...f.geometry.coordinates.map((coords) =>
pointToLineDistance(point, lineString(coords))
)
pointToLineDistance(point, lineString(coords)),
),
);
} else {
return Infinity;
@ -30,8 +30,11 @@ export async function getMeta(coord: WorldLocation, layer: string) {
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");
if(filtered.length === 0) return null;
const filtered = features.filter(
(f) =>
f.geometry.type === "LineString" || f.geometry.type == "MultiLineString",
);
if (filtered.length === 0) return null;
const nearest = filtered.reduce((a, b) => {
const distA = getFeatureDistance(a, [coord.lon, coord.lat]);
const distB = getFeatureDistance(b, [coord.lon, coord.lat]);
@ -44,16 +47,16 @@ const IMPLICIT_SPEEDS: Record<string, number> = {
"DE:urban": 50,
"DE:rural": 100, // TODO: 80 (hgv weight > 3.5t, or trailer), 60 (weight > 7.5t)
"DE:living_street": 7,
"DE:bicycle_road": 30
}
"DE:bicycle_road": 30,
};
export function getSpeed(maxspeed: string): number | null {
if(!isNaN(parseInt(maxspeed))) return parseInt(maxspeed);
if(maxspeed.endsWith(" mph")) {
if (!isNaN(parseInt(maxspeed))) return parseInt(maxspeed);
if (maxspeed.endsWith(" mph")) {
const val = parseInt(maxspeed.replace(" mph", ""));
if(!isNaN(val)) return Math.round(val * 1.60934); // Convert to km/h
if (!isNaN(val)) return Math.round(val * 1.60934); // Convert to km/h
}
if(maxspeed === "walk") return 7; // https://wiki.openstreetmap.org/wiki/Proposed_features/maxspeed_walk
if (maxspeed === "walk") return 7; // https://wiki.openstreetmap.org/wiki/Proposed_features/maxspeed_walk
return IMPLICIT_SPEEDS[maxspeed as keyof typeof IMPLICIT_SPEEDS] || null;
}
@ -64,11 +67,11 @@ function coordToTile(coord: WorldLocation, zoom: number) {
((1 -
Math.log(
Math.tan((coord.lat * Math.PI) / 180) +
1 / Math.cos((coord.lat * Math.PI) / 180)
1 / Math.cos((coord.lat * Math.PI) / 180),
) /
Math.PI) /
2) *
Math.pow(2, z)
Math.pow(2, z),
);
return { z, x, y };
}
@ -117,7 +120,7 @@ export async function fetchTile(z: number, x: number, y: number) {
const pmtiles = (await hasPMTiles("tiles"))
? new PMTiles(new FSSource("tiles"))
: new PMTiles("https://trafficcue-tiles.picoscratch.de/germany.pmtiles");
const tile = (await pmtiles.getZxy(z, x, y));
const tile = await pmtiles.getZxy(z, x, y);
if (!tile) {
console.log(tile);
throw new Error(`Tile not found: z${z} x${x} y${y}`);