osmix 0.0.2 → 0.0.6

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +177 -0
  3. package/dist/src/extract.d.ts +43 -0
  4. package/dist/src/extract.d.ts.map +1 -0
  5. package/dist/src/extract.js +156 -0
  6. package/dist/src/extract.js.map +1 -0
  7. package/dist/src/index.d.ts +58 -0
  8. package/dist/src/index.d.ts.map +1 -0
  9. package/dist/src/index.js +60 -0
  10. package/dist/src/index.js.map +1 -0
  11. package/dist/src/osmix.worker.d.ts +22 -0
  12. package/dist/src/osmix.worker.d.ts.map +1 -0
  13. package/dist/src/osmix.worker.js +24 -0
  14. package/dist/src/osmix.worker.js.map +1 -0
  15. package/dist/src/pbf.d.ts +55 -0
  16. package/dist/src/pbf.d.ts.map +1 -0
  17. package/dist/src/pbf.js +187 -0
  18. package/dist/src/pbf.js.map +1 -0
  19. package/dist/src/raster.d.ts +28 -0
  20. package/dist/src/raster.d.ts.map +1 -0
  21. package/dist/src/raster.js +82 -0
  22. package/dist/src/raster.js.map +1 -0
  23. package/dist/src/remote.d.ts +289 -0
  24. package/dist/src/remote.d.ts.map +1 -0
  25. package/dist/src/remote.js +426 -0
  26. package/dist/src/remote.js.map +1 -0
  27. package/dist/src/settings.d.ts +9 -0
  28. package/dist/src/settings.d.ts.map +1 -0
  29. package/dist/src/settings.js +12 -0
  30. package/dist/src/settings.js.map +1 -0
  31. package/dist/src/utils.d.ts +36 -0
  32. package/dist/src/utils.d.ts.map +1 -0
  33. package/dist/src/utils.js +108 -0
  34. package/dist/src/utils.js.map +1 -0
  35. package/dist/src/worker.d.ts +232 -0
  36. package/dist/src/worker.d.ts.map +1 -0
  37. package/dist/src/worker.js +375 -0
  38. package/dist/src/worker.js.map +1 -0
  39. package/dist/test/extract.bench.d.ts +2 -0
  40. package/dist/test/extract.bench.d.ts.map +1 -0
  41. package/dist/test/extract.bench.js +26 -0
  42. package/dist/test/extract.bench.js.map +1 -0
  43. package/dist/test/extract.test.d.ts +2 -0
  44. package/dist/test/extract.test.d.ts.map +1 -0
  45. package/dist/test/extract.test.js +392 -0
  46. package/dist/test/extract.test.js.map +1 -0
  47. package/dist/test/merge.test.d.ts +2 -0
  48. package/dist/test/merge.test.d.ts.map +1 -0
  49. package/dist/test/merge.test.js +163 -0
  50. package/dist/test/merge.test.js.map +1 -0
  51. package/dist/test/read-pbf.test.d.ts +2 -0
  52. package/dist/test/read-pbf.test.d.ts.map +1 -0
  53. package/dist/test/read-pbf.test.js +17 -0
  54. package/dist/test/read-pbf.test.js.map +1 -0
  55. package/dist/test/remote.test.d.ts +2 -0
  56. package/dist/test/remote.test.d.ts.map +1 -0
  57. package/dist/test/remote.test.js +215 -0
  58. package/dist/test/remote.test.js.map +1 -0
  59. package/dist/test/write-pbf.test.d.ts +2 -0
  60. package/dist/test/write-pbf.test.d.ts.map +1 -0
  61. package/dist/test/write-pbf.test.js +55 -0
  62. package/dist/test/write-pbf.test.js.map +1 -0
  63. package/package.json +13 -6
  64. package/src/extract.ts +181 -0
  65. package/src/index.ts +55 -0
  66. package/src/osmix.worker.ts +25 -0
  67. package/src/pbf.ts +255 -0
  68. package/src/raster.ts +97 -0
  69. package/src/remote.ts +579 -0
  70. package/src/settings.ts +14 -0
  71. package/src/utils.ts +119 -0
  72. package/src/worker.ts +499 -0
  73. package/test/extract.bench.ts +34 -0
  74. package/test/extract.test.ts +518 -0
  75. package/test/merge.test.ts +202 -0
  76. package/test/read-pbf.test.ts +22 -0
  77. package/test/remote.test.ts +319 -0
  78. package/test/write-pbf.test.ts +69 -0
  79. package/dist/index.d.ts +0 -7
  80. package/dist/index.d.ts.map +0 -1
  81. package/dist/index.js +0 -7
  82. package/dist/index.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,78 @@
1
1
  # osmix
2
2
 
3
+ ## 0.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 0cd8a2e: Explore patterns for extending Osmix worker
8
+ - Updated dependencies [3846a0c]
9
+ - Updated dependencies [2c03b6c]
10
+ - Updated dependencies [0cd8a2e]
11
+ - Updated dependencies [cdab4db]
12
+ - @osmix/change@0.0.6
13
+ - @osmix/core@0.0.6
14
+ - @osmix/vt@0.0.6
15
+ - @osmix/shared@0.0.6
16
+ - @osmix/geojson@0.0.4
17
+ - @osmix/json@0.0.6
18
+ - @osmix/pbf@0.0.3
19
+ - @osmix/raster@0.0.6
20
+
21
+ ## 0.0.5
22
+
23
+ ### Patch Changes
24
+
25
+ - bb629cf: Simplify raster drawing when geometry is smaller than a pixel
26
+ - 345b716: Move functionality outside of the Changeset
27
+ - edbb26b: Handle more Relation types
28
+ - 45b1802: Add `transformOsmPbfToJson` helper
29
+ - 69a36bd: Switch Nodes coordinate storage to Int32Array
30
+ - Updated dependencies [bb629cf]
31
+ - Updated dependencies [a33a280]
32
+ - Updated dependencies [345b716]
33
+ - Updated dependencies [edbb26b]
34
+ - Updated dependencies [69a36bd]
35
+ - @osmix/raster@0.0.5
36
+ - @osmix/shared@0.0.5
37
+ - @osmix/vt@0.0.5
38
+ - @osmix/core@0.0.5
39
+ - @osmix/change@0.0.5
40
+ - @osmix/geojson@0.0.3
41
+ - @osmix/json@0.0.5
42
+ - @osmix/pbf@0.0.3
43
+
44
+ ## 0.0.4
45
+
46
+ ### Patch Changes
47
+
48
+ - d001d9a: Refactor to align around new main external API
49
+ - Updated dependencies [572cbd8]
50
+ - Updated dependencies [d001d9a]
51
+ - Updated dependencies [b2f14d3]
52
+ - Updated dependencies [4303c40]
53
+ - @osmix/raster@0.0.4
54
+ - @osmix/shared@0.0.4
55
+ - @osmix/geojson@0.0.2
56
+ - @osmix/change@0.0.4
57
+ - @osmix/core@0.0.4
58
+ - @osmix/json@0.0.4
59
+ - @osmix/pbf@0.0.3
60
+ - @osmix/vt@0.0.4
61
+
62
+ ## 0.0.3
63
+
64
+ ### Patch Changes
65
+
66
+ - Updated dependencies [b4a3ff2]
67
+ - Updated dependencies [c0193dd]
68
+ - @osmix/raster@0.0.3
69
+ - @osmix/shared@0.0.3
70
+ - @osmix/core@0.0.3
71
+ - @osmix/json@0.0.3
72
+ - @osmix/vt@0.0.3
73
+ - @osmix/change@0.0.3
74
+ - @osmix/pbf@0.0.2
75
+
3
76
  ## 0.0.2
4
77
 
5
78
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # osmix
2
+
3
+ `osmix` is the high-level entrypoint for the Osmix toolkit. It layers ingestion,
4
+ streaming, and worker orchestration utilities on top of the low-level
5
+ `@osmix/core` index so you can load `.osm.pbf` files, convert GeoJSON, and
6
+ request raster/vector tiles with a single import.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ bun install osmix
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ### Load a PBF and inspect it
17
+
18
+ ```ts
19
+ import { fromPbf, fromGeoJSON, toPbfBuffer } from "osmix"
20
+
21
+ const monacoPbf = await Bun.file("./monaco.pbf").arrayBuffer()
22
+ const osm = await fromPbf(monacoPbf)
23
+
24
+ console.log(osm.nodes.size, osm.ways.size, osm.relations.size)
25
+
26
+ const geojsonFile = await fetch("/fixtures/buildings.geojson").then((r) => r.arrayBuffer())
27
+ const geoOsm = await fromGeoJSON(geojsonFile)
28
+ const pbfBytes = await toPbfBuffer(geoOsm)
29
+ ```
30
+
31
+ ### Work off the main thread with `OsmixRemote`
32
+
33
+ ```ts
34
+ import { createRemote } from "osmix"
35
+
36
+ const remote = await createRemote()
37
+ const monacoOsmInfo = await remote.fromPbf(monacoPbf)
38
+ const patchOsmInfo = await remote.fromPbf(Bun.file("patch.osm.pbf").stream(), {
39
+ id: "patch",
40
+ })
41
+ await remote.merge(monacoOsmInfo, patchOsmInfo)
42
+ const rasterTile = await remote.getRasterTile(monacoOsmInfo, [10561, 22891, 16])
43
+ ```
44
+
45
+ #### How?
46
+
47
+ `OsmixRemote` automatically transfers typed arrays across workers (using
48
+ `SharedArrayBuffer` when available) and exposes the same helpers exposed in the main import: `fromPbf`, `fromGeoJSON`, `getVectorTile`, `getRasterTile`,
49
+ `search`, `merge`, `generateChangeset`, etc. Use `collectTransferables` +
50
+ `transfer` when you need to post Osmix payloads through your own worker setup.
51
+
52
+ ### Routing with workers
53
+
54
+ `OsmixRemote` provides off-thread routing via `@osmix/router`. The routing graph
55
+ builds lazily on first use, so there's no upfront cost until you actually route.
56
+
57
+ ```ts
58
+ import { createRemote } from "osmix"
59
+
60
+ const remote = await createRemote()
61
+ const osmInfo = await remote.fromPbf(monacoPbf)
62
+
63
+ // Find nearest routable nodes to coordinates
64
+ const from = await remote.findNearestRoutableNode(osmInfo.id, [7.42, 43.73], 0.5)
65
+ const to = await remote.findNearestRoutableNode(osmInfo.id, [7.43, 43.74], 0.5)
66
+
67
+ if (from && to) {
68
+ // Calculate route with statistics and path info
69
+ const result = await remote.route(osmInfo.id, from.nodeIndex, to.nodeIndex, {
70
+ includeStats: true,
71
+ includePathInfo: true,
72
+ })
73
+
74
+ if (result) {
75
+ console.log(result.coordinates) // Route geometry
76
+ console.log(result.distance) // Distance in meters
77
+ console.log(result.time) // Time in seconds
78
+ console.log(result.segments) // Per-way breakdown
79
+ }
80
+ }
81
+ ```
82
+
83
+ The routing graph is automatically shared across all workers when using
84
+ `SharedArrayBuffer`, so any worker can handle routing requests.
85
+
86
+ ### Extract, stream, and write back to PBF
87
+
88
+ ```ts
89
+ import { fromPbf, createExtract, toPbfStream } from "osmix"
90
+
91
+ const osm = await fromPbf(Bun.file('./monaco.pbf').stream())
92
+ const downtown = createExtract(osm, [-122.35, 47.60, -122.32, 47.62])
93
+ await toPbfStream(downtown).pipeTo(fileWritableStream)
94
+ ```
95
+
96
+ `createExtract` can either clip ways/members to the bbox (`strategy: "simple"`)
97
+ or include complete ways/relations. `toPbfStream` and `toPbfBuffer`
98
+ reuse the streaming builders from `@osmix/json`/`@osmix/pbf`, so outputs stay
99
+ spec-compliant without staging everything in memory.
100
+
101
+ ## API
102
+
103
+ ### Loading
104
+
105
+ - `fromPbf(data, options?)` - Load OSM data from PBF (buffer, stream, or File).
106
+ - `fromGeoJSON(data, options?)` - Load OSM data from GeoJSON.
107
+ - `readOsmPbfHeader(data)` - Read only the PBF header without loading entities.
108
+
109
+ ### Export
110
+
111
+ - `toPbfStream(osm)` - Stream Osm to PBF bytes (memory-efficient).
112
+ - `toPbfBuffer(osm)` - Convert Osm to a single PBF buffer.
113
+
114
+ ### Extraction
115
+
116
+ - `createExtract(osm, bbox, strategy?)` - Create geographic extract.
117
+ - `"simple"` - Strict spatial cut.
118
+ - `"complete_ways"` - Include complete way geometry.
119
+ - `"smart"` - Complete ways + resolved multipolygons.
120
+
121
+ ### Tiles
122
+
123
+ - `drawToRasterTile(osm, tile, tileSize?)` - Render Osm to raster tile.
124
+
125
+ ### Workers (OsmixRemote)
126
+
127
+ - `createRemote(options?)` - Create worker pool manager.
128
+ - `remote.fromPbf(data, options?)` - Load in worker.
129
+ - `remote.fromGeoJSON(data, options?)` - Load in worker.
130
+ - `remote.getVectorTile(osmId, tile)` - Generate MVT in worker.
131
+ - `remote.getRasterTile(osmId, tile, tileSize?)` - Generate raster in worker.
132
+ - `remote.merge(baseId, patchId, options?)` - Merge datasets in worker.
133
+ - `remote.search(osmId, key, val?)` - Search by tag.
134
+ - `remote.toPbf(osmId, stream)` - Export to PBF.
135
+
136
+ #### Routing
137
+
138
+ - `remote.buildRoutingGraph(osmId, filter?, speeds?)` - Explicitly build routing graph (optional, builds lazily on first use).
139
+ - `remote.hasRoutingGraph(osmId)` - Check if routing graph exists.
140
+ - `remote.findNearestRoutableNode(osmId, point, maxKm)` - Snap coordinate to nearest routable node.
141
+ - `remote.route(osmId, fromIndex, toIndex, options?)` - Calculate route between nodes.
142
+ - `options.includeStats` - Include `distance` and `time` in result.
143
+ - `options.includePathInfo` - Include `segments` and `turnPoints` in result.
144
+
145
+ ### Utilities
146
+
147
+ - `collectTransferables(value)` - Find transferable buffers in nested objects.
148
+ - `transfer(data)` - Wrap data for zero-copy worker transfer.
149
+
150
+ ## Related Packages
151
+
152
+ - [`@osmix/core`](../core/README.md) - In-memory OSM index with typed arrays and spatial queries.
153
+ - [`@osmix/pbf`](../pbf/README.md) - Low-level PBF reading and writing.
154
+ - [`@osmix/json`](../json/README.md) - PBF to JSON entity conversion.
155
+ - [`@osmix/geojson`](../geojson/README.md) - GeoJSON import/export.
156
+ - [`@osmix/change`](../change/README.md) - Changeset management and merge workflows.
157
+ - [`@osmix/raster`](../raster/README.md) - Raster tile rendering.
158
+ - [`@osmix/vt`](../vt/README.md) - Vector tile encoding.
159
+ - [`@osmix/router`](../router/README.md) - Pathfinding on OSM road networks.
160
+ - [`@osmix/shared`](../shared/README.md) - Shared utilities and types.
161
+
162
+ ## Environment and limitations
163
+
164
+ - Requires runtimes that expose Web Streams plus modern typed array + compression
165
+ APIs (Node 20+, Bun, current browsers). `OsmixRemote` also requires `Worker`
166
+ support and, for multi-worker concurrency, `SharedArrayBuffer`.
167
+ - `fromPbf` expects dense-node blocks; sparse node encodings are not yet supported.
168
+ - Raster helpers rely on `OffscreenCanvas` + `ImageData`.
169
+
170
+ ## Development
171
+
172
+ - `bun run test packages/osmix`
173
+ - `bun run lint packages/osmix`
174
+ - `bun run typecheck packages/osmix`
175
+
176
+ Run `bun run check` from the repo root before publishing to keep formatting,
177
+ lint, and types consistent.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Geographic extraction from OSM indexes.
3
+ *
4
+ * Creates subsets of OSM data within bounding boxes using various strategies
5
+ * that control how ways and relations at the boundary are handled.
6
+ *
7
+ * @module
8
+ */
9
+ import { Osm } from "@osmix/core";
10
+ import { type ProgressEvent } from "@osmix/shared/progress";
11
+ import type { GeoBbox2D } from "@osmix/shared/types";
12
+ /**
13
+ * Strategy for handling entities at extract boundaries.
14
+ * - `"simple"`: Strict spatial cut, may have incomplete geometries.
15
+ * - `"complete_ways"`: Preserves complete way geometry, adds nodes outside bbox.
16
+ * - `"smart"`: Like complete_ways, plus fully resolves multipolygon relations.
17
+ */
18
+ export type ExtractStrategy = "simple" | "complete_ways" | "smart";
19
+ /**
20
+ * Create a geographic extract from an existing Osm instance within a bounding box.
21
+ *
22
+ * Strategy "simple":
23
+ * 1. Selects all nodes inside the bbox.
24
+ * 2. Selects ways with at least one node inside the bbox, filtering refs to only include nodes inside the bbox.
25
+ * 3. Selects relations with at least one member inside the bbox, filtering members to only include nodes and ways inside the bbox.
26
+ *
27
+ * Strategy "complete_ways":
28
+ * 1. Selects all nodes inside the bbox.
29
+ * 2. Selects ways with at least one node inside the bbox, adding missing way nodes from outside the bbox. All ways will be reference complete.
30
+ * 3. Selects relations with at least one member inside the bbox leaving out any members that are not inside the bbox. Relations are not reference complete.
31
+ *
32
+ * Strategy "smart":
33
+ * 1 & 2. Same as "complete_ways".
34
+ * 3. Selects relations with at least one member inside the bbox, adding missing relation members from outside the bbox. Relations are reference complete.
35
+ *
36
+ * The "complete_ways" strategy preserves way geometry integrity but includes entities outside the bbox.
37
+ * The "simple" strategy creates a strict spatial cut but may result in incomplete geometries.
38
+ * Both strategies handle nested relations by resolving all descendant members.
39
+ *
40
+ * See https://osmcode.org/osmium-tool/manual.html#creating-geographic-extracts for more details.
41
+ */
42
+ export declare function createExtract(osm: Osm, bbox: GeoBbox2D, strategy?: ExtractStrategy, onProgress?: (progress: ProgressEvent) => void): Osm;
43
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/extract.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAEN,KAAK,aAAa,EAElB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAA;AAGjE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,eAAe,GAAG,OAAO,CAAA;AAElE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,SAAS,EACf,QAAQ,GAAE,eAAiC,EAC3C,UAAU,GAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAkB,GACzD,GAAG,CA6HL"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Geographic extraction from OSM indexes.
3
+ *
4
+ * Creates subsets of OSM data within bounding boxes using various strategies
5
+ * that control how ways and relations at the boundary are handled.
6
+ *
7
+ * @module
8
+ */
9
+ import { Osm } from "@osmix/core";
10
+ import { logProgress, progressEvent, } from "@osmix/shared/progress";
11
+ import { resolveRelationMembers } from "@osmix/shared/relation-kind";
12
+ import { isMultipolygonRelation } from "@osmix/shared/utils";
13
+ /**
14
+ * Create a geographic extract from an existing Osm instance within a bounding box.
15
+ *
16
+ * Strategy "simple":
17
+ * 1. Selects all nodes inside the bbox.
18
+ * 2. Selects ways with at least one node inside the bbox, filtering refs to only include nodes inside the bbox.
19
+ * 3. Selects relations with at least one member inside the bbox, filtering members to only include nodes and ways inside the bbox.
20
+ *
21
+ * Strategy "complete_ways":
22
+ * 1. Selects all nodes inside the bbox.
23
+ * 2. Selects ways with at least one node inside the bbox, adding missing way nodes from outside the bbox. All ways will be reference complete.
24
+ * 3. Selects relations with at least one member inside the bbox leaving out any members that are not inside the bbox. Relations are not reference complete.
25
+ *
26
+ * Strategy "smart":
27
+ * 1 & 2. Same as "complete_ways".
28
+ * 3. Selects relations with at least one member inside the bbox, adding missing relation members from outside the bbox. Relations are reference complete.
29
+ *
30
+ * The "complete_ways" strategy preserves way geometry integrity but includes entities outside the bbox.
31
+ * The "simple" strategy creates a strict spatial cut but may result in incomplete geometries.
32
+ * Both strategies handle nested relations by resolving all descendant members.
33
+ *
34
+ * See https://osmcode.org/osmium-tool/manual.html#creating-geographic-extracts for more details.
35
+ */
36
+ export function createExtract(osm, bbox, strategy = "complete_ways", onProgress = logProgress) {
37
+ if (!osm.isReady())
38
+ throw Error("Osm is not ready for extraction.");
39
+ onProgress(progressEvent(`Creating extract ${osm.id} with strategy=${strategy} in bbox ${bbox.join(", ")}...`));
40
+ const [minLon, minLat, maxLon, maxLat] = bbox;
41
+ const extracted = new Osm({
42
+ id: osm.id,
43
+ header: {
44
+ ...osm.header,
45
+ bbox: {
46
+ left: minLon,
47
+ bottom: minLat,
48
+ right: maxLon,
49
+ top: maxLat,
50
+ },
51
+ },
52
+ });
53
+ const nodeIds = new Set();
54
+ const wayIds = new Set();
55
+ const relationIds = new Set();
56
+ const addNodeIfMissing = (id) => {
57
+ if (nodeIds.has(id))
58
+ return;
59
+ const node = osm.nodes.getById(id);
60
+ if (!node)
61
+ throw Error(`Node ${id} not found`);
62
+ extracted.nodes.addNode(node);
63
+ nodeIds.add(id);
64
+ };
65
+ const addWayIfMissing = (id) => {
66
+ if (wayIds.has(id))
67
+ return;
68
+ const way = osm.ways.getById(id);
69
+ if (!way)
70
+ throw Error(`Way ${id} not found`);
71
+ for (const ref of way.refs)
72
+ addNodeIfMissing(ref);
73
+ extracted.ways.addWay(way);
74
+ wayIds.add(id);
75
+ };
76
+ const addRelationIfMissing = (relation) => {
77
+ if (relationIds.has(relation.id))
78
+ return;
79
+ relationIds.add(relation.id);
80
+ for (const member of relation.members) {
81
+ if (member.type === "node")
82
+ addNodeIfMissing(member.ref);
83
+ if (member.type === "way")
84
+ addWayIfMissing(member.ref);
85
+ if (member.type === "relation") {
86
+ const nestedRelation = osm.relations.getById(member.ref);
87
+ if (nestedRelation)
88
+ addRelationIfMissing(nestedRelation);
89
+ }
90
+ }
91
+ extracted.relations.addRelation(relation);
92
+ };
93
+ onProgress(progressEvent("Extracting nodes..."));
94
+ for (const nodeIndex of osm.nodes.findIndexesWithinBbox(bbox)) {
95
+ const node = osm.nodes.getByIndex(nodeIndex);
96
+ extracted.nodes.addNode(node);
97
+ nodeIds.add(node.id);
98
+ }
99
+ onProgress(progressEvent("Extracting ways..."));
100
+ for (const way of osm.ways.sorted()) {
101
+ if (way.refs.some((ref) => nodeIds.has(ref))) {
102
+ wayIds.add(way.id);
103
+ if (strategy === "complete_ways" || strategy === "smart") {
104
+ for (const ref of way.refs)
105
+ addNodeIfMissing(ref);
106
+ extracted.ways.addWay(way);
107
+ }
108
+ else if (strategy === "simple") {
109
+ extracted.ways.addWay({
110
+ ...way,
111
+ refs: way.refs.filter((ref) => nodeIds.has(ref)),
112
+ });
113
+ }
114
+ }
115
+ }
116
+ onProgress(progressEvent("Extracting relations..."));
117
+ for (const relation of osm.relations.sorted()) {
118
+ // Resolve nested relations to get all descendant nodes and ways
119
+ const resolved = resolveRelationMembers(relation, (relId) => osm.relations.getById(relId), 10);
120
+ // Check if relation has any members that intersect the bbox
121
+ const hasIntersectingMembers = resolved.nodes.some((id) => nodeIds.has(id)) ||
122
+ resolved.ways.some((id) => wayIds.has(id));
123
+ if (hasIntersectingMembers) {
124
+ if (isMultipolygonRelation(relation) && strategy === "smart") {
125
+ // Add relation and recursively add direct members even if they're outside the bbox
126
+ addRelationIfMissing(relation);
127
+ }
128
+ else {
129
+ // Otherwise, filter out members that are outside the bbox
130
+ extracted.relations.addRelation({
131
+ ...relation,
132
+ members: relation.members.filter((m) => {
133
+ if (m.type === "node")
134
+ return nodeIds.has(m.ref);
135
+ if (m.type === "way")
136
+ return wayIds.has(m.ref);
137
+ if (m.type === "relation") {
138
+ const nestedRelation = osm.relations.getById(m.ref);
139
+ if (!nestedRelation)
140
+ return false;
141
+ // Include nested relation if it has intersecting members
142
+ const nestedResolved = resolveRelationMembers(nestedRelation, (relId) => osm.relations.getById(relId));
143
+ return (nestedResolved.nodes.some((id) => nodeIds.has(id)) ||
144
+ nestedResolved.ways.some((id) => wayIds.has(id)));
145
+ }
146
+ return false;
147
+ }),
148
+ });
149
+ }
150
+ }
151
+ }
152
+ extracted.buildIndexes();
153
+ extracted.buildSpatialIndexes();
154
+ return extracted;
155
+ }
156
+ //# sourceMappingURL=extract.js.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wBACtC,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;4BAAE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;wBAChD,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK;4BAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;wBAC9C,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;4BAC3B,MAAM,cAAc,GAAG,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;4BACnD,IAAI,CAAC,cAAc;gCAAE,OAAO,KAAK,CAAA;4BACjC,yDAAyD;4BACzD,MAAM,cAAc,GAAG,sBAAsB,CAC5C,cAAc,EACd,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CACvC,CAAA;4BACD,OAAO,CACN,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gCAClD,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAChD,CAAA;wBACF,CAAC;wBACD,OAAO,KAAK,CAAA;oBACb,CAAC,CAAC;iBACF,CAAC,CAAA;YACH,CAAC;QACF,CAAC;IACF,CAAC;IAED,SAAS,CAAC,YAAY,EAAE,CAAA;IACxB,SAAS,CAAC,mBAAmB,EAAE,CAAA;IAC/B,OAAO,SAAS,CAAA;AACjB,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * osmix - High-level entrypoint for the Osmix toolkit.
3
+ *
4
+ * This package provides a unified API for loading, manipulating, and exporting
5
+ * OpenStreetMap data. It layers ingestion, streaming, and worker orchestration
6
+ * on top of the lower-level @osmix/* packages.
7
+ *
8
+ * Key capabilities:
9
+ * - **Loading**: Load PBF files and GeoJSON into memory-efficient Osm indexes.
10
+ * - **Streaming**: Convert between PBF and JSON entity streams.
11
+ * - **Extraction**: Create geographic extracts with various strategies.
12
+ * - **Tiles**: Generate raster and vector tiles from OSM data.
13
+ * - **Workers**: Offload heavy operations to Web Workers with `OsmixRemote`.
14
+ * - **Merging**: Combine datasets with deduplication and intersection creation.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { fromPbf, toPbfBuffer, createExtract } from "osmix"
19
+ *
20
+ * // Load from PBF
21
+ * const osm = await fromPbf(pbfFile.stream())
22
+ *
23
+ * // Create extract
24
+ * const downtown = createExtract(osm, [-122.35, 47.60, -122.32, 47.62])
25
+ *
26
+ * // Export to PBF
27
+ * const pbfBytes = await toPbfBuffer(downtown)
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // Use workers for off-thread processing
33
+ * import { createRemote } from "osmix"
34
+ *
35
+ * const remote = await createRemote()
36
+ * const osmInfo = await remote.fromPbf(pbfFile)
37
+ * const tile = await remote.getVectorTile(osmInfo.id, [9372, 12535, 15])
38
+ * ```
39
+ *
40
+ * @module osmix
41
+ */
42
+ export * from "@osmix/change";
43
+ export * from "@osmix/core";
44
+ export * from "@osmix/geojson";
45
+ export * from "@osmix/json";
46
+ export * from "@osmix/pbf";
47
+ export * from "@osmix/raster";
48
+ export * from "@osmix/router";
49
+ export * from "@osmix/shared/types";
50
+ export * from "@osmix/vt";
51
+ export * from "./extract";
52
+ export * from "./pbf";
53
+ export * from "./raster";
54
+ export * from "./remote";
55
+ export * from "./settings";
56
+ export * from "./utils";
57
+ export * from "./worker";
58
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAGH,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,WAAW,CAAA;AAGzB,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * osmix - High-level entrypoint for the Osmix toolkit.
3
+ *
4
+ * This package provides a unified API for loading, manipulating, and exporting
5
+ * OpenStreetMap data. It layers ingestion, streaming, and worker orchestration
6
+ * on top of the lower-level @osmix/* packages.
7
+ *
8
+ * Key capabilities:
9
+ * - **Loading**: Load PBF files and GeoJSON into memory-efficient Osm indexes.
10
+ * - **Streaming**: Convert between PBF and JSON entity streams.
11
+ * - **Extraction**: Create geographic extracts with various strategies.
12
+ * - **Tiles**: Generate raster and vector tiles from OSM data.
13
+ * - **Workers**: Offload heavy operations to Web Workers with `OsmixRemote`.
14
+ * - **Merging**: Combine datasets with deduplication and intersection creation.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { fromPbf, toPbfBuffer, createExtract } from "osmix"
19
+ *
20
+ * // Load from PBF
21
+ * const osm = await fromPbf(pbfFile.stream())
22
+ *
23
+ * // Create extract
24
+ * const downtown = createExtract(osm, [-122.35, 47.60, -122.32, 47.62])
25
+ *
26
+ * // Export to PBF
27
+ * const pbfBytes = await toPbfBuffer(downtown)
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // Use workers for off-thread processing
33
+ * import { createRemote } from "osmix"
34
+ *
35
+ * const remote = await createRemote()
36
+ * const osmInfo = await remote.fromPbf(pbfFile)
37
+ * const tile = await remote.getVectorTile(osmInfo.id, [9372, 12535, 15])
38
+ * ```
39
+ *
40
+ * @module osmix
41
+ */
42
+ // Re-export core libraries
43
+ export * from "@osmix/change";
44
+ export * from "@osmix/core";
45
+ export * from "@osmix/geojson";
46
+ export * from "@osmix/json";
47
+ export * from "@osmix/pbf";
48
+ export * from "@osmix/raster";
49
+ export * from "@osmix/router";
50
+ export * from "@osmix/shared/types";
51
+ export * from "@osmix/vt";
52
+ // Export new utilities
53
+ export * from "./extract";
54
+ export * from "./pbf";
55
+ export * from "./raster";
56
+ export * from "./remote";
57
+ export * from "./settings";
58
+ export * from "./utils";
59
+ export * from "./worker";
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,2BAA2B;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,WAAW,CAAA;AAEzB,uBAAuB;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Default OsmixWorker entry point.
3
+ *
4
+ * This file serves as the default worker entry point that exposes a standard OsmixWorker.
5
+ * For custom workers, import {OsmixWorker} from "osmix" instead to avoid the side effect.
6
+ *
7
+ * @example
8
+ * // Using the default worker (via OsmixRemote with no workerUrl)
9
+ * const remote = await createRemote()
10
+ *
11
+ * @example
12
+ * // Custom worker - import from worker to avoid side effects
13
+ * import { OsmixWorker } from "osmix"
14
+ * import { expose } from "comlink"
15
+ *
16
+ * class MyWorker extends OsmixWorker {
17
+ * myMethod() { ... }
18
+ * }
19
+ * expose(new MyWorker())
20
+ */
21
+ export {};
22
+ //# sourceMappingURL=osmix.worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osmix.worker.d.ts","sourceRoot":"","sources":["../../src/osmix.worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Default OsmixWorker entry point.
3
+ *
4
+ * This file serves as the default worker entry point that exposes a standard OsmixWorker.
5
+ * For custom workers, import {OsmixWorker} from "osmix" instead to avoid the side effect.
6
+ *
7
+ * @example
8
+ * // Using the default worker (via OsmixRemote with no workerUrl)
9
+ * const remote = await createRemote()
10
+ *
11
+ * @example
12
+ * // Custom worker - import from worker to avoid side effects
13
+ * import { OsmixWorker } from "osmix"
14
+ * import { expose } from "comlink"
15
+ *
16
+ * class MyWorker extends OsmixWorker {
17
+ * myMethod() { ... }
18
+ * }
19
+ * expose(new MyWorker())
20
+ */
21
+ import { expose } from "comlink";
22
+ import { OsmixWorker } from "./worker";
23
+ expose(new OsmixWorker());
24
+ //# sourceMappingURL=osmix.worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osmix.worker.js","sourceRoot":"","sources":["../../src/osmix.worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA"}