-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
323 lines (302 loc) · 9.34 KB
/
index.html
File metadata and controls
323 lines (302 loc) · 9.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Osmix - OSM Toolkit for the Browser</title>
<link href="main.css" rel="stylesheet" />
<script src="client.ts" type="module" defer></script>
</head>
<body>
<main>
<header>
<h1>OSMIX</h1>
<p class="tagline">OpenStreetMap toolkit for the browser</p>
<nav>
<a href="https://github.com/conveyal/osmix" target="_blank">GitHub Repo</a>
<a href="https://merge.osmix.dev" target="_blank">Merge App</a>
<a href="https://deepwiki.com/conveyal/osmix" target="_blank">Docs (by DeepWiki)</a>
</nav>
</header>
<div class="admin-only">
<button id="clear-db-btn" type="button">Clear IndexedDB</button>
</div>
<section id="intro">
<h2>About</h2>
<p>
Osmix is a high-level toolkit for loading, manipulating, and
exporting OpenStreetMap data in the browser. It provides streaming
PBF parsing, memory-efficient indexing, raster/vector tile
generation, routing, and merge workflows - all running off the main
thread via Web Workers.
</p>
</section>
<section id="installation">
<h2>Installation</h2>
<p>Install the <code>osmix</code> package with your package manager of choice.</p>
<pre><code class="highlight-this" data-lang="bash">$ bun add osmix</code></pre>
</section>
<section id="examples">
<h2>Examples</h2>
<div class="file-input">
<div class="button-group">
<label id="load-file">
Open an OSM PBF File
<input
type="file"
id="file-input-el"
accept=".pbf,.osm.pbf"
/>
</label>
<button id="load-monaco" type="button">use monaco.pbf</button>
</div>
<div id="loading-status"></div>
</div>
<div class="example">
<h3>1. Load File and Get Stats</h3>
<p>Load an OSM PBF file and extract basic statistics including node, way, and relation counts, plus the geographic bounding box.</p>
<pre><code id="code-stats" class="highlight-this" data-lang="typescript">import { createRemote } from "osmix"
const remote = await createRemote()
const osm = await remote.fromPbf(pbfFile)
console.log("Nodes:", osm.stats.nodes)
console.log("Ways:", osm.stats.ways)
console.log("Relations:", osm.stats.relations)
console.log("Bbox:", osm.bbox)</code></pre>
<div class="result-box" id="stats-result">
<p class="placeholder">Select a file above to see results...</p>
</div>
</div>
<div class="example">
<h3>2. Render Raster Tiles to Canvas</h3>
<p>Fetch OSM raster tiles directly from Osmix and draw a static preview onto a canvas element without a map library.</p>
<pre><code id="code-map" class="highlight-this" data-lang="typescript">import { createRemote } from "osmix"
const remote = await createRemote()
const osm = await remote.fromPbf(pbfFile)
const zoom = 14
const tileSize = 256
const [minX, minY, maxX, maxY] = bboxToTileRange(osm.bbox, zoom)
const canvas = document.getElementById("map-canvas") as HTMLCanvasElement
const ctx = canvas.getContext("2d")
for (const [x, y] of listTiles(minX, minY, maxX, maxY)) {
const tile = await osm.getRasterTile([x, y, zoom], tileSize)
const image = new ImageData(tile, tileSize, tileSize)
ctx.putImageData(image, (x - minX) * tileSize, (y - minY) * tileSize)
}</code></pre>
<div class="result-box" id="map-result">
<p class="placeholder">Select a file above to render tiles...</p>
<canvas id="map-canvas"></canvas>
</div>
</div>
<div class="example">
<h3>3. Search Tags</h3>
<p>Query OSM elements by tag key and optional value, returning matching nodes, ways, and relations from the loaded dataset.</p>
<pre><code id="code-search" class="highlight-this" data-lang="typescript">import { createRemote } from "osmix"
const remote = await createRemote()
const osm = await remote.fromPbf(pbfFile)
const results = await osm.search("amenity", "restaurant")
console.log("Nodes:", results.nodes.length)
console.log("Ways:", results.ways.length)
console.log("Relations:", results.relations.length)</code></pre>
<div class="search-controls">
<input
type="text"
id="search-key"
placeholder="Tag key (e.g., amenity)"
/>
<input type="text" id="search-value" placeholder="Value (optional)" />
<button id="search-btn" type="button" disabled>Search</button>
</div>
<div class="result-box" id="search-result">
<p class="placeholder">
Select a file and enter a search query...
</p>
<table id="search-table">
<thead>
<tr>
<th>Type</th>
<th>ID</th>
<th>Tags</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="example">
<h3>4. Routing</h3>
<p>Calculate routes between points on the road network. Click the map to set origin and destination, with automatic snapping to the nearest routable node.</p>
<pre class="terminal"><code id="code-routing" class="highlight-this" data-lang="typescript">import { createRemote } from "osmix"
const remote = await createRemote()
const osm = await remote.fromPbf(pbfFile)
// Click on map to set origin and destination
map.on('click', async (e) => {
const point = [e.lngLat.lng, e.lngLat.lat]
const snapped = await osm.findNearestRoutableNode(point, 500)
if (snapped) {
// Use snapped.nodeIndex for routing
}
})
// Calculate route between two snapped nodes
const result = await osm.route(
fromNode.nodeIndex,
toNode.nodeIndex,
{ includeStats: true, includePathInfo: true }
)</code></pre>
<div class="result-box" id="routing-result">
<p class="placeholder">
Select a file above, then click on the map to set origin and
destination...
</p>
<div id="route-map"></div>
<table id="route-table">
<thead>
<tr>
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</section>
<section id="packages">
<h2>Packages</h2>
<p>Osmix is a collection of packages that work together to provide a complete toolkit for working with OpenStreetMap data. You can use each package individually or together to build your own workflow.</p>
<table>
<thead>
<tr>
<th>Package</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/core"
>@osmix/core</a
>
</td>
<td>In-memory OSM index with typed arrays and spatial queries</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/pbf"
>@osmix/pbf</a
>
</td>
<td>Low-level PBF reading and writing</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/json"
>@osmix/json</a
>
</td>
<td>PBF to JSON entity conversion</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/geojson"
>@osmix/geojson</a
>
</td>
<td>GeoJSON import/export</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/geoparquet"
>@osmix/geoparquet</a
>
</td>
<td>GeoParquet import</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/gtfs"
>@osmix/gtfs</a
>
</td>
<td>GTFS feed import</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/shapefile"
>@osmix/shapefile</a
>
</td>
<td>Shapefile import</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/change"
>@osmix/change</a
>
</td>
<td>Changeset generation and merge workflows</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/raster"
>@osmix/raster</a
>
</td>
<td>Raster tile rendering</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/vt"
>@osmix/vt</a
>
</td>
<td>Vector tile encoding (MVT)</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/shortbread"
>@osmix/shortbread</a
>
</td>
<td>Shortbread schema vector tiles</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/router"
>@osmix/router</a
>
</td>
<td>Pathfinding on OSM road networks</td>
</tr>
<tr>
<td>
<a
href="https://github.com/conveyal/osmix/tree/main/packages/shared"
>@osmix/shared</a
>
</td>
<td>Shared utilities and types</td>
</tr>
</tbody>
</table>
</section>
<footer>
<nav>
<a href="https://github.com/conveyal/osmix">GitHub</a>
<a href="https://conveyal.com">Conveyal</a>
</nav>
</footer>
</main>
</body>
</html>