@osmix/core 0.0.1 → 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.
- package/CHANGELOG.md +52 -0
- package/README.md +118 -107
- package/dist/core/src/entities.d.ts +114 -0
- package/dist/core/src/entities.d.ts.map +1 -0
- package/dist/core/src/entities.js +152 -0
- package/dist/core/src/entities.js.map +1 -0
- package/dist/core/src/ids.d.ts +113 -0
- package/dist/core/src/ids.d.ts.map +1 -0
- package/dist/core/src/ids.js +236 -0
- package/dist/core/src/ids.js.map +1 -0
- package/dist/core/src/index.d.ts +32 -0
- package/dist/core/src/index.d.ts.map +1 -0
- package/dist/core/src/index.js +35 -0
- package/dist/core/src/index.js.map +1 -0
- package/dist/core/src/nodes.d.ts +101 -0
- package/dist/core/src/nodes.d.ts.map +1 -0
- package/dist/core/src/nodes.js +309 -0
- package/dist/core/src/nodes.js.map +1 -0
- package/dist/core/src/osm.d.ts +74 -0
- package/dist/core/src/osm.d.ts.map +1 -0
- package/dist/core/src/osm.js +120 -0
- package/dist/core/src/osm.js.map +1 -0
- package/dist/core/src/relations.d.ts +118 -0
- package/dist/core/src/relations.d.ts.map +1 -0
- package/dist/core/src/relations.js +412 -0
- package/dist/core/src/relations.js.map +1 -0
- package/dist/core/src/stringtable.d.ts +95 -0
- package/dist/core/src/stringtable.d.ts.map +1 -0
- package/dist/core/src/stringtable.js +170 -0
- package/dist/core/src/stringtable.js.map +1 -0
- package/dist/core/src/tags.d.ts +126 -0
- package/dist/core/src/tags.d.ts.map +1 -0
- package/dist/core/src/tags.js +228 -0
- package/dist/core/src/tags.js.map +1 -0
- package/dist/core/src/typed-arrays.d.ts +124 -0
- package/dist/core/src/typed-arrays.d.ts.map +1 -0
- package/dist/core/src/typed-arrays.js +198 -0
- package/dist/core/src/typed-arrays.js.map +1 -0
- package/dist/core/src/utils.d.ts +11 -0
- package/dist/core/src/utils.d.ts.map +1 -0
- package/dist/core/src/utils.js +26 -0
- package/dist/core/src/utils.js.map +1 -0
- package/dist/core/src/ways.d.ts +101 -0
- package/dist/core/src/ways.d.ts.map +1 -0
- package/dist/core/src/ways.js +336 -0
- package/dist/core/src/ways.js.map +1 -0
- package/dist/core/test/memory.test.d.ts +7 -0
- package/dist/core/test/memory.test.d.ts.map +1 -0
- package/dist/core/test/memory.test.js +29 -0
- package/dist/core/test/memory.test.js.map +1 -0
- package/dist/core/test/mock-osm.d.ts +13 -0
- package/dist/core/test/mock-osm.d.ts.map +1 -0
- package/dist/core/test/mock-osm.js +122 -0
- package/dist/core/test/mock-osm.js.map +1 -0
- package/dist/core/test/tags-search.test.d.ts +2 -0
- package/dist/core/test/tags-search.test.d.ts.map +1 -0
- package/dist/core/test/tags-search.test.js +56 -0
- package/dist/core/test/tags-search.test.js.map +1 -0
- package/dist/core/test/typed-arrays.test.d.ts +2 -0
- package/dist/core/test/typed-arrays.test.d.ts.map +1 -0
- package/dist/core/test/typed-arrays.test.js +102 -0
- package/dist/core/test/typed-arrays.test.js.map +1 -0
- package/dist/osmix/src/extract.d.ts +43 -0
- package/dist/osmix/src/extract.d.ts.map +1 -0
- package/dist/osmix/src/extract.js +156 -0
- package/dist/osmix/src/extract.js.map +1 -0
- package/dist/osmix/src/pbf.d.ts +55 -0
- package/dist/osmix/src/pbf.d.ts.map +1 -0
- package/dist/osmix/src/pbf.js +187 -0
- package/dist/osmix/src/pbf.js.map +1 -0
- package/dist/osmix/src/utils.d.ts +36 -0
- package/dist/osmix/src/utils.d.ts.map +1 -0
- package/dist/osmix/src/utils.js +108 -0
- package/dist/osmix/src/utils.js.map +1 -0
- package/dist/osmix/test/extract.bench.d.ts +2 -0
- package/dist/osmix/test/extract.bench.d.ts.map +1 -0
- package/dist/osmix/test/extract.bench.js +26 -0
- package/dist/osmix/test/extract.bench.js.map +1 -0
- package/dist/osmix/test/extract.test.d.ts +2 -0
- package/dist/osmix/test/extract.test.d.ts.map +1 -0
- package/dist/osmix/test/extract.test.js +392 -0
- package/dist/osmix/test/extract.test.js.map +1 -0
- package/package.json +11 -11
- package/src/entities.ts +138 -22
- package/src/ids.ts +117 -45
- package/src/index.ts +34 -5
- package/src/nodes.ts +237 -58
- package/src/osm.ts +174 -0
- package/src/relations.ts +383 -54
- package/src/stringtable.ts +111 -36
- package/src/tags.ts +207 -46
- package/src/typed-arrays.ts +97 -10
- package/src/types/geoflatbush.d.ts +37 -0
- package/src/types/geokdbush.d.ts +37 -0
- package/src/types/kdbush.d.ts +24 -6
- package/src/utils.ts +9 -14
- package/src/ways.ts +248 -84
- package/test/memory.test.ts +38 -0
- package/test/mock-osm.ts +8 -8
- package/test/tags-search.test.ts +60 -0
- package/test/typed-arrays.test.ts +5 -6
- package/tsconfig.json +7 -1
- package/src/osmix.ts +0 -556
- package/test/extract.bench.ts +0 -29
- package/test/extract.test.ts +0 -156
- package/test/read.test.ts +0 -22
- package/test/write.test.ts +0 -66
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resizable typed array utilities.
|
|
3
|
+
*
|
|
4
|
+
* Wraps typed arrays with automatic buffer expansion (ArrayList semantics).
|
|
5
|
+
* Uses SharedArrayBuffer (if available) for zero-copy worker transfer.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Use SharedArrayBuffer if the runtime supports it, otherwise fall back to ArrayBuffer.
|
|
11
|
+
* SharedArrayBuffer enables zero-copy transfer between workers.
|
|
12
|
+
*/
|
|
13
|
+
export const BufferConstructor = typeof SharedArrayBuffer !== "undefined"
|
|
14
|
+
? SharedArrayBuffer
|
|
15
|
+
: ArrayBuffer;
|
|
16
|
+
/**
|
|
17
|
+
* Float64Array for storing OSM IDs.
|
|
18
|
+
*
|
|
19
|
+
* OSM IDs are 64-bit integers. JavaScript's number type (IEEE 754 double)
|
|
20
|
+
* can exactly represent integers up to 2^53, which covers all current OSM IDs.
|
|
21
|
+
* Float64Array allows typed array operations while maintaining precision.
|
|
22
|
+
*/
|
|
23
|
+
export const IdArrayType = Float64Array;
|
|
24
|
+
/**
|
|
25
|
+
* Uint32Array for storing array indices.
|
|
26
|
+
*
|
|
27
|
+
* Internal indices into typed arrays never exceed 2^32 elements,
|
|
28
|
+
* so Uint32Array provides the best balance of range and memory efficiency.
|
|
29
|
+
*/
|
|
30
|
+
export const IndexArrayType = Uint32Array;
|
|
31
|
+
/**
|
|
32
|
+
* Initial buffer size for ResizeableTypedArray.
|
|
33
|
+
* 1 MiB provides reasonable initial capacity while avoiding excessive memory allocation.
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_BUFFER_SIZE = 2 ** 20; // 1 MiB
|
|
36
|
+
/**
|
|
37
|
+
* Auto-expanding typed array wrapper.
|
|
38
|
+
*
|
|
39
|
+
* - `push()` appends elements, doubling buffer size as needed.
|
|
40
|
+
* - `compact()` shrinks buffer to fit data.
|
|
41
|
+
* - Supports growable SharedArrayBuffer and resizable ArrayBuffer.
|
|
42
|
+
*/
|
|
43
|
+
export class ResizeableTypedArray {
|
|
44
|
+
/** The typed array constructor for this instance */
|
|
45
|
+
ArrayType;
|
|
46
|
+
/** The current typed array view into the buffer */
|
|
47
|
+
array;
|
|
48
|
+
/** Number of items actually stored (may be less than array.length) */
|
|
49
|
+
items = 0;
|
|
50
|
+
/** The underlying ArrayBuffer or SharedArrayBuffer */
|
|
51
|
+
buffer;
|
|
52
|
+
/** Current buffer size in bytes */
|
|
53
|
+
bufferSize;
|
|
54
|
+
/** Maximum byte length for growable buffers */
|
|
55
|
+
maxByteLength;
|
|
56
|
+
/** Buffer constructor (SharedArrayBuffer or ArrayBuffer) */
|
|
57
|
+
BC;
|
|
58
|
+
/**
|
|
59
|
+
* Reconstruct a ResizeableTypedArray from an existing buffer.
|
|
60
|
+
*
|
|
61
|
+
* Used after transferring buffers between workers. The resulting array
|
|
62
|
+
* is considered "compacted" with items = array.length.
|
|
63
|
+
*
|
|
64
|
+
* @param ArrayType - The typed array constructor.
|
|
65
|
+
* @param buffer - The existing buffer to wrap.
|
|
66
|
+
* @returns A new ResizeableTypedArray wrapping the buffer.
|
|
67
|
+
*/
|
|
68
|
+
static from(ArrayType, buffer) {
|
|
69
|
+
const rta = new ResizeableTypedArray(ArrayType, buffer instanceof SharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer);
|
|
70
|
+
rta.buffer = buffer;
|
|
71
|
+
rta.array = new ArrayType(buffer);
|
|
72
|
+
rta.items = rta.array.length;
|
|
73
|
+
return rta;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a new ResizeableTypedArray with an empty buffer.
|
|
77
|
+
*
|
|
78
|
+
* @param ArrayType - The typed array constructor (e.g., Float64Array).
|
|
79
|
+
* @param BC - Buffer constructor to use (defaults to SharedArrayBuffer if available).
|
|
80
|
+
*/
|
|
81
|
+
constructor(ArrayType, BC = BufferConstructor) {
|
|
82
|
+
this.ArrayType = ArrayType;
|
|
83
|
+
this.bufferSize = DEFAULT_BUFFER_SIZE;
|
|
84
|
+
this.maxByteLength = DEFAULT_BUFFER_SIZE * 2;
|
|
85
|
+
this.BC = BC;
|
|
86
|
+
this.buffer = new BC(this.bufferSize, {
|
|
87
|
+
maxByteLength: this.maxByteLength,
|
|
88
|
+
});
|
|
89
|
+
this.array = new this.ArrayType(this.buffer);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Iterate over the array values.
|
|
93
|
+
*/
|
|
94
|
+
[Symbol.iterator]() {
|
|
95
|
+
return this.array[Symbol.iterator]();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Double the buffer capacity.
|
|
99
|
+
* Uses in-place grow/resize if supported, otherwise allocates new buffer and copies.
|
|
100
|
+
*/
|
|
101
|
+
expandArray() {
|
|
102
|
+
this.bufferSize *= 2;
|
|
103
|
+
if (this.bufferSize > this.buffer.maxByteLength) {
|
|
104
|
+
// Need a completely new buffer with larger maxByteLength
|
|
105
|
+
this.maxByteLength *= 2;
|
|
106
|
+
const newBuffer = new this.BC(this.bufferSize, {
|
|
107
|
+
maxByteLength: this.maxByteLength,
|
|
108
|
+
});
|
|
109
|
+
const newArray = new this.ArrayType(newBuffer);
|
|
110
|
+
newArray.set(this.array);
|
|
111
|
+
this.buffer = newBuffer;
|
|
112
|
+
this.array = newArray;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Can grow/resize the existing buffer in place
|
|
116
|
+
if (this.buffer instanceof SharedArrayBuffer && this.buffer.growable) {
|
|
117
|
+
this.buffer.grow(this.bufferSize);
|
|
118
|
+
}
|
|
119
|
+
else if (this.buffer instanceof ArrayBuffer && this.buffer.resizable) {
|
|
120
|
+
this.buffer.resize(this.bufferSize);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
throw Error("Buffer is not growable or resizable");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get the value at an index. Handles negative indices.
|
|
129
|
+
*/
|
|
130
|
+
at(index) {
|
|
131
|
+
if (index < -this.length || index >= this.length)
|
|
132
|
+
throw Error(`Index out of bounds: ${index}. Length: ${this.length}`);
|
|
133
|
+
if (index < 0)
|
|
134
|
+
return this.at(this.length + index);
|
|
135
|
+
const result = this.array[index];
|
|
136
|
+
if (result === undefined)
|
|
137
|
+
throw Error(`No value at index: ${index}`);
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get a slice of the array.
|
|
142
|
+
*/
|
|
143
|
+
slice(start, end) {
|
|
144
|
+
return this.array.slice(start, end);
|
|
145
|
+
}
|
|
146
|
+
get length() {
|
|
147
|
+
return this.items;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Push a value to the end of the array.
|
|
151
|
+
*/
|
|
152
|
+
push(value) {
|
|
153
|
+
if (this.length >= this.array.length) {
|
|
154
|
+
this.expandArray();
|
|
155
|
+
}
|
|
156
|
+
this.array[this.items++] = value;
|
|
157
|
+
return this.length - 1;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Set a value at a specific index. Expands array if needed.
|
|
161
|
+
*/
|
|
162
|
+
set(index, value) {
|
|
163
|
+
if (index < 0)
|
|
164
|
+
throw Error("Index out of bounds");
|
|
165
|
+
if (index >= this.length) {
|
|
166
|
+
while (index >= this.array.length)
|
|
167
|
+
this.expandArray();
|
|
168
|
+
this.items = index + 1;
|
|
169
|
+
}
|
|
170
|
+
this.array[index] = value;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Push multiple values to the end of the array.
|
|
174
|
+
*/
|
|
175
|
+
pushMany(values) {
|
|
176
|
+
while (this.length + values.length > this.array.length)
|
|
177
|
+
this.expandArray();
|
|
178
|
+
this.array.set(values, this.length);
|
|
179
|
+
this.items += values.length;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Shrink the buffer to exactly fit stored items.
|
|
183
|
+
* Buffer becomes fixed-length after compacting.
|
|
184
|
+
*/
|
|
185
|
+
compact() {
|
|
186
|
+
if (this.buffer instanceof SharedArrayBuffer) {
|
|
187
|
+
// SharedArrayBuffer uses slice() to create a new fixed-size buffer
|
|
188
|
+
this.buffer = this.buffer.slice(0, this.length * this.ArrayType.BYTES_PER_ELEMENT);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// ArrayBuffer uses transferToFixedLength() to detach and resize
|
|
192
|
+
this.buffer = this.buffer.transferToFixedLength(this.length * this.ArrayType.BYTES_PER_ELEMENT);
|
|
193
|
+
}
|
|
194
|
+
this.array = new this.ArrayType(this.buffer);
|
|
195
|
+
return this.array;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=typed-arrays.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-arrays.js","sourceRoot":"","sources":["../../../src/typed-arrays.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,i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AI,CAAC,KAAK,CAAA;IAClB,CAAC;CACD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for @osmix/core.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type { GeoBbox2D, LonLat } from "@osmix/shared/types";
|
|
6
|
+
/**
|
|
7
|
+
* Compute the bounding box of a set of coordinates.
|
|
8
|
+
* Returns `[minLon, minLat, maxLon, maxLat]`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function bboxFromLonLats(lonLats: LonLat[]): GeoBbox2D;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5D;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAY5D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for @osmix/core.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compute the bounding box of a set of coordinates.
|
|
7
|
+
* Returns `[minLon, minLat, maxLon, maxLat]`.
|
|
8
|
+
*/
|
|
9
|
+
export function bboxFromLonLats(lonLats) {
|
|
10
|
+
let minLon = Number.POSITIVE_INFINITY;
|
|
11
|
+
let minLat = Number.POSITIVE_INFINITY;
|
|
12
|
+
let maxLon = Number.NEGATIVE_INFINITY;
|
|
13
|
+
let maxLat = Number.NEGATIVE_INFINITY;
|
|
14
|
+
for (const [lon, lat] of lonLats) {
|
|
15
|
+
if (lon < minLon)
|
|
16
|
+
minLon = lon;
|
|
17
|
+
if (lat < minLat)
|
|
18
|
+
minLat = lat;
|
|
19
|
+
if (lon > maxLon)
|
|
20
|
+
maxLon = lon;
|
|
21
|
+
if (lat > maxLat)
|
|
22
|
+
maxLat = lat;
|
|
23
|
+
}
|
|
24
|
+
return [minLon, minLat, maxLon, maxLat];
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAAiB;IAChD,IAAI,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAA;IACrC,IAAI,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAA;IACrC,IAAI,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAA;IACrC,IAAI,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAA;IACrC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;QAClC,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAA;QAC9B,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAA;QAC9B,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAA;QAC9B,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAA;IAC/B,CAAC;IACD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AACxC,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { OsmPbfWay } from "@osmix/pbf";
|
|
2
|
+
import type { GeoBbox2D, LonLat, OsmTags, OsmWay } from "@osmix/shared/types";
|
|
3
|
+
import Flatbush from "flatbush";
|
|
4
|
+
import { Entities, type EntitiesTransferables } from "./entities";
|
|
5
|
+
import { type IdOrIndex } from "./ids";
|
|
6
|
+
import type { Nodes } from "./nodes";
|
|
7
|
+
import type StringTable from "./stringtable";
|
|
8
|
+
import { type BufferType } from "./typed-arrays";
|
|
9
|
+
export interface WaysTransferables<T extends BufferType = BufferType> extends EntitiesTransferables<T> {
|
|
10
|
+
refStart: T;
|
|
11
|
+
refCount: T;
|
|
12
|
+
refs: T;
|
|
13
|
+
bbox: T;
|
|
14
|
+
/** Optional - can be rebuilt via buildSpatialIndex() */
|
|
15
|
+
spatialIndex?: T;
|
|
16
|
+
}
|
|
17
|
+
export declare class Ways extends Entities<OsmWay> {
|
|
18
|
+
private spatialIndex;
|
|
19
|
+
private spatialIndexBuilt;
|
|
20
|
+
private refStart;
|
|
21
|
+
private refCount;
|
|
22
|
+
private refs;
|
|
23
|
+
private bbox;
|
|
24
|
+
private nodes;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new Ways index.
|
|
27
|
+
*/
|
|
28
|
+
constructor(stringTable: StringTable, nodes: Nodes, transferables?: WaysTransferables);
|
|
29
|
+
/**
|
|
30
|
+
* Add a single way to the index.
|
|
31
|
+
*/
|
|
32
|
+
addWay(way: OsmWay): number;
|
|
33
|
+
/**
|
|
34
|
+
* Bulk add ways directly from a PBF PrimitiveBlock.
|
|
35
|
+
*/
|
|
36
|
+
addWays(ways: OsmPbfWay[], blockStringIndexMap: Uint32Array, filter?: (way: OsmWay) => OsmWay | null): number;
|
|
37
|
+
/**
|
|
38
|
+
* Compact the internal arrays to free up memory.
|
|
39
|
+
*/
|
|
40
|
+
buildEntityIndex(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Build the spatial index for ways.
|
|
43
|
+
* If bbox data already exists (e.g., loaded from storage), reuses it.
|
|
44
|
+
*/
|
|
45
|
+
buildSpatialIndex(): Flatbush;
|
|
46
|
+
/**
|
|
47
|
+
* Check if the spatial index has been built.
|
|
48
|
+
*/
|
|
49
|
+
hasSpatialIndex(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Get the full way entity.
|
|
52
|
+
*/
|
|
53
|
+
getFullEntity(index: number, id: number, tags?: OsmTags): OsmWay;
|
|
54
|
+
/**
|
|
55
|
+
* Get the node IDs referenced by a way.
|
|
56
|
+
*/
|
|
57
|
+
getRefIds(index: number): number[];
|
|
58
|
+
/**
|
|
59
|
+
* Get the bounding box of a way.
|
|
60
|
+
*/
|
|
61
|
+
getEntityBbox(idOrIndex: IdOrIndex): GeoBbox2D;
|
|
62
|
+
/**
|
|
63
|
+
* Get the coordinates of a way as a flat array.
|
|
64
|
+
*/
|
|
65
|
+
getLine(index: number): Float64Array<ArrayBuffer>;
|
|
66
|
+
/**
|
|
67
|
+
* Get the coordinates of a way as an array of [lon, lat] pairs.
|
|
68
|
+
*/
|
|
69
|
+
getCoordinates(index: number): LonLat[];
|
|
70
|
+
/**
|
|
71
|
+
* Find way indexes that intersect a bounding box.
|
|
72
|
+
*/
|
|
73
|
+
intersects(bbox: GeoBbox2D, filterFn?: (index: number) => boolean): number[];
|
|
74
|
+
/**
|
|
75
|
+
* Find way indexes near a point using great-circle distance.
|
|
76
|
+
* @param lon - Longitude in degrees.
|
|
77
|
+
* @param lat - Latitude in degrees.
|
|
78
|
+
* @param maxResults - Maximum number of results to return.
|
|
79
|
+
* @param maxDistanceKm - Maximum distance in kilometers.
|
|
80
|
+
* @returns Array of way indexes sorted by distance.
|
|
81
|
+
*/
|
|
82
|
+
neighbors(lon: number, lat: number, maxResults?: number, maxDistanceKm?: number): number[];
|
|
83
|
+
/**
|
|
84
|
+
* Get ways within a bounding box.
|
|
85
|
+
*/
|
|
86
|
+
withinBbox(bbox: GeoBbox2D, include?: (index: number) => boolean): {
|
|
87
|
+
ids: Float64Array;
|
|
88
|
+
positions: Float64Array;
|
|
89
|
+
startIndices: Uint32Array;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Get transferable objects for passing to another thread.
|
|
93
|
+
* Only includes spatialIndex if it has been built.
|
|
94
|
+
*/
|
|
95
|
+
transferables(): WaysTransferables;
|
|
96
|
+
/**
|
|
97
|
+
* Get the approximate memory requirements for a given number of ways in bytes.
|
|
98
|
+
*/
|
|
99
|
+
static getBytesRequired(count: number): number;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=ways.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ways.d.ts","sourceRoot":"","sources":["../../../src/ways.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC7E,OAAO,QAAQ,MAAM,UAAU,CAAA;AAE/B,OAAO,EAAE,QAAQ,EAAE,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,KAAK,SAAS,EAAO,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAA;AAE5C,OAAO,EAEN,KAAK,UAAU,EAGf,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CACnE,SAAQ,qBAAqB,CAAC,CAAC,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAA;IACX,QAAQ,EAAE,CAAC,CAAA;IACX,IAAI,EAAE,CAAC,CAAA;IACP,IAAI,EAAE,CAAC,CAAA;IACP,wDAAwD;IACxD,YAAY,CAAC,EAAE,CAAC,CAAA;CAChB;AAED,qBAAa,IAAK,SAAQ,QAAQ,CAAC,MAAM,CAAC;IACzC,OAAO,CAAC,YAAY,CAA4B;IAEhD,OAAO,CAAC,iBAAiB,CAAQ;IAEjC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,QAAQ,CAAkB;IAGlC,OAAO,CAAC,IAAI,CAAmB;IAG/B,OAAO,CAAC,IAAI,CAAmB;IAG/B,OAAO,CAAC,KAAK,CAAO;IAEpB;;OAEG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