Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 136 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"stream": "0.0.2",
"timers": "^0.1.1",
"timers-browserify": "^2.0.12",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"xml2js": "^0.6.2"
},
Expand Down Expand Up @@ -60,6 +61,7 @@
},
"homepage": "",
"devDependencies": {
"@types/mapbox-gl": "^2.7.14",
"@types/xml2js": "^0.4.12"
}
}
11 changes: 9 additions & 2 deletions src/api/osm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { parseStringPromise } from 'xml2js';
import { Way } from '../types';
import { tagListToRecord } from '../utils/utils';

export async function getOsmNodePosition(osmNode: string | number): Promise<{ lat: number, lon: number, tags: Record<string, string> }> {

export async function getOsmNodePosition(osmNode: number): Promise<{ lat: number, lon: number, osmNodeID: number, tags: Record<string, string> }> {
try {
const response: string = await (await fetch(`https://api.openstreetmap.org/api/0.6/node/${osmNode}`)).text();
const osmApiResult = await parseStringPromise(response);

Expand All @@ -21,7 +23,12 @@ export async function getOsmNodePosition(osmNode: string | number): Promise<{ la
tags[tag.$.k] = tag.$.v;
});

return { lat, lon, tags };
return { lat, lon, tags, osmNodeID: osmNode };
}catch(e) {
console.log(`Error fetching OSM node ${osmNode}: ${e}`);
throw e;

}
}

export async function fetchOsmWaysForNode(nodeId: string | number): Promise<Way[]> {
Expand Down
12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,15 @@ export interface SQLIntersectionWithId extends SQLIntersection {
/** Unique serial id of intersection measurement */
id: string; // Using string for uuid
}


/** A basic cache for the https://api.openstreetmap.org/api/0.6/node/... endpoint */
export type OSMNodePositionCache = Record<number, OSMNodePosition>;

/** Info returned from the OSM API */
interface OSMNodePosition {
lat: number,
lon: number
/** OSM tags for the given node */
tags: Record<string, string>;
}
19 changes: 11 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"ts-node": {
// these options are overrides used only by ts-node
// same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"typeRoots": ["./node_modules/@types"]
}
},
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand All @@ -19,7 +24,5 @@
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
"include": ["src"]
}