@osm-editor-kit/osm-data 0.1.0-alpha.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/types/osm-data.d.ts +2 -3
- package/package.json +6 -10
package/README.md
CHANGED
|
@@ -1,23 +1,62 @@
|
|
|
1
1
|
# `@osm-editor-kit/osm-data`
|
|
2
2
|
|
|
3
|
+
Download OSM JSON from Overpass or the OSM API, parse it into an indexed in-memory store, and merge several downloads into one. For apps that show or check OSM data.
|
|
4
|
+
|
|
3
5
|
> [!NOTE]
|
|
4
|
-
>
|
|
6
|
+
> Claude Opus 5.5 wrote and reviewed the code of this package. [@tordans](https://github.com/tordans) specified what it should do and tested and verified its user-facing behavior.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @osm-editor-kit/osm-data
|
|
12
|
+
```
|
|
5
13
|
|
|
6
14
|
## What it does
|
|
7
15
|
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
16
|
+
- Fetches OSM JSON from a URL (Overpass or OSM API).
|
|
17
|
+
- Parses `elements` into indexes by id: ways, relations, tagged nodes, and node coordinates (`[lat, lon]`).
|
|
18
|
+
- Marks which ways are members of a relation (`waysInRelation`).
|
|
19
|
+
- Merges two parsed stores. Ways and relations keep the higher `version`; nodes and coordinates from the newer store replace existing ones.
|
|
20
|
+
- Exports TypeScript types for OSM elements and the parsed store.
|
|
21
|
+
|
|
22
|
+
It only fetches, parses, and indexes. It does not edit OSM data or write tags.
|
|
13
23
|
|
|
14
24
|
## Usage
|
|
15
25
|
|
|
16
26
|
```ts
|
|
17
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
downloadOsmData,
|
|
29
|
+
emptyParsedOsmData,
|
|
30
|
+
mergeParsedOsm,
|
|
31
|
+
parseOsmResp,
|
|
32
|
+
type ParsedOsmData,
|
|
33
|
+
type RawOsmData,
|
|
34
|
+
} from '@osm-editor-kit/osm-data'
|
|
35
|
+
|
|
36
|
+
// Download from a URL that returns OSM JSON (throws when the request fails, for example HTTP 429)
|
|
37
|
+
const downloaded: ParsedOsmData = await downloadOsmData(
|
|
38
|
+
'https://overpass-api.de/api/interpreter?data=[out:json];way(52.47,13.44,52.48,13.45)[highway];out;',
|
|
39
|
+
)
|
|
18
40
|
|
|
19
|
-
|
|
20
|
-
const
|
|
41
|
+
// Or parse a response you already have
|
|
42
|
+
const raw: RawOsmData = { elements: [] }
|
|
43
|
+
const parsed = parseOsmResp(raw)
|
|
44
|
+
|
|
45
|
+
// Merge into one store; start from an empty store if you have nothing yet
|
|
46
|
+
const store = mergeParsedOsm(emptyParsedOsmData(), downloaded)
|
|
47
|
+
const combined = mergeParsedOsm(store, parsed)
|
|
48
|
+
|
|
49
|
+
combined.ways[42]?.tags.highway
|
|
50
|
+
combined.nodeCoords[10] // [lat, lon]
|
|
51
|
+
combined.waysInRelation[42] // true when a parsed relation lists way 42
|
|
21
52
|
```
|
|
22
53
|
|
|
23
|
-
|
|
54
|
+
Notes:
|
|
55
|
+
|
|
56
|
+
- `parseOsmResp` throws on element types other than `node`, `way`, and `relation`.
|
|
57
|
+
- `waysInRelation` only marks ways that appear in the response before the relation. Overpass lists ways before relations, so this works with its default output.
|
|
58
|
+
- Only nodes with tags are stored in `nodes`. All nodes are stored in `nodeCoords`.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { downloadOsmData, emptyParsedOsmData, mergeParsedOsm, parseOsmResp } from './data-client';
|
|
2
2
|
export type { LatLngLiteral, MapBounds } from './types/geo';
|
|
3
|
-
export type { OsmElement, OsmNode, OsmObject, OsmRelation, OsmTags, OsmWay, RawOsmData, } from './types/osm-data';
|
|
3
|
+
export type { OsmElement, OsmNode, OsmObject, OsmRelation, OsmTags, OsmType, OsmWay, RawOsmData, RelationMember, } from './types/osm-data';
|
|
4
4
|
export type { ParsedOsmData, WaysInRelation } from './types/osm-data-storage';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
1
|
// src/data-client.ts
|
|
4
2
|
function emptyParsedOsmData() {
|
|
5
3
|
return {
|
|
@@ -40,12 +38,13 @@ async function downloadOsmData(url) {
|
|
|
40
38
|
return parseOsmResp(osmResp);
|
|
41
39
|
}
|
|
42
40
|
async function downloadContent(url) {
|
|
43
|
-
const resp = await
|
|
41
|
+
const resp = await fetch(url, {
|
|
44
42
|
headers: {
|
|
45
43
|
Accept: "application/json"
|
|
46
44
|
}
|
|
47
45
|
});
|
|
48
|
-
|
|
46
|
+
if (!resp.ok) throw new Error(`Request failed with status code ${resp.status}`);
|
|
47
|
+
return resp.json();
|
|
49
48
|
}
|
|
50
49
|
function parseOsmResp(osmResp) {
|
|
51
50
|
const newData = emptyParsedOsmData();
|
package/dist/types/osm-data.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type OsmTags = Record<string, string>;
|
|
2
|
-
type OsmType = 'node' | 'way' | 'relation';
|
|
2
|
+
export type OsmType = 'node' | 'way' | 'relation';
|
|
3
3
|
export interface OsmObject {
|
|
4
4
|
id: number;
|
|
5
5
|
type: OsmType;
|
|
@@ -11,7 +11,7 @@ export interface OsmObject {
|
|
|
11
11
|
changeset: number;
|
|
12
12
|
tags: OsmTags;
|
|
13
13
|
}
|
|
14
|
-
interface RelationMember {
|
|
14
|
+
export interface RelationMember {
|
|
15
15
|
type: OsmType;
|
|
16
16
|
ref: number;
|
|
17
17
|
role: string;
|
|
@@ -33,4 +33,3 @@ export type OsmElement = OsmNode | OsmWay | OsmRelation;
|
|
|
33
33
|
export interface RawOsmData {
|
|
34
34
|
elements: OsmElement[];
|
|
35
35
|
}
|
|
36
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osm-editor-kit/osm-data",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Download, parse, and merge OSM API/Overpass responses into an indexed in-memory store.",
|
|
5
|
+
"homepage": "https://github.com/osm-editor-kit/street-space-editor/tree/main/packages/osm-data",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"author": "Tobias Jordans",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
10
|
+
"url": "git+https://github.com/osm-editor-kit/street-space-editor.git",
|
|
10
11
|
"directory": "packages/osm-data"
|
|
11
12
|
},
|
|
12
|
-
"homepage": "https://github.com/osmberlin/street-space-editor/tree/main/packages/osm-data",
|
|
13
|
-
"type": "module",
|
|
14
|
-
"sideEffects": false,
|
|
15
13
|
"files": [
|
|
16
14
|
"dist"
|
|
17
15
|
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
|
-
"access": "public"
|
|
27
|
-
"tag": "alpha"
|
|
26
|
+
"access": "public"
|
|
28
27
|
},
|
|
29
28
|
"scripts": {
|
|
30
29
|
"build": "tsup && rm -f .tsbuildinfo && tsc -p tsconfig.build.json",
|
|
@@ -35,9 +34,6 @@
|
|
|
35
34
|
"prepack": "bun ../../scripts/package-exports-for-publish.ts",
|
|
36
35
|
"postpack": "bun ../../scripts/package-exports-restore.ts"
|
|
37
36
|
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"axios": "^1.11.0"
|
|
40
|
-
},
|
|
41
37
|
"devDependencies": {
|
|
42
38
|
"bun-types": "^1.2.20",
|
|
43
39
|
"tsup": "^8.5.1",
|