@osmix/shared 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 +33 -0
- package/README.md +49 -19
- package/dist/src/assert.d.ts +24 -0
- package/dist/src/assert.d.ts.map +1 -0
- package/dist/src/assert.js +28 -0
- package/dist/src/assert.js.map +1 -0
- package/dist/src/bbox-intersects.d.ts +15 -0
- package/dist/src/bbox-intersects.d.ts.map +1 -0
- package/dist/src/bbox-intersects.js +24 -0
- package/dist/src/bbox-intersects.js.map +1 -0
- package/dist/src/bytes-to-stream.d.ts +18 -0
- package/dist/src/bytes-to-stream.d.ts.map +1 -0
- package/dist/src/bytes-to-stream.js +25 -0
- package/dist/src/bytes-to-stream.js.map +1 -0
- package/dist/src/concat-bytes.d.ts +5 -0
- package/dist/src/concat-bytes.d.ts.map +1 -0
- package/dist/src/concat-bytes.js +14 -0
- package/dist/src/concat-bytes.js.map +1 -0
- package/dist/src/coordinates.d.ts +28 -0
- package/dist/src/coordinates.d.ts.map +1 -0
- package/dist/src/coordinates.js +38 -0
- package/dist/src/coordinates.js.map +1 -0
- package/dist/src/haversine-distance.d.ts +16 -0
- package/dist/src/haversine-distance.d.ts.map +1 -0
- package/dist/src/haversine-distance.js +26 -0
- package/dist/src/haversine-distance.js.map +1 -0
- package/dist/src/lineclip.d.ts +2 -0
- package/dist/src/lineclip.d.ts.map +1 -0
- package/dist/src/lineclip.js +3 -0
- package/dist/src/lineclip.js.map +1 -0
- package/dist/src/progress.d.ts +40 -0
- package/dist/src/progress.d.ts.map +1 -0
- package/dist/src/progress.js +40 -0
- package/dist/src/progress.js.map +1 -0
- package/dist/src/relation-kind.d.ts +69 -0
- package/dist/src/relation-kind.d.ts.map +1 -0
- package/dist/src/relation-kind.js +375 -0
- package/dist/src/relation-kind.js.map +1 -0
- package/dist/src/relation-multipolygon.d.ts +43 -0
- package/dist/src/relation-multipolygon.d.ts.map +1 -0
- package/dist/src/relation-multipolygon.js +195 -0
- package/dist/src/relation-multipolygon.js.map +1 -0
- package/dist/src/stream-to-bytes.d.ts +18 -0
- package/dist/src/stream-to-bytes.d.ts.map +1 -0
- package/dist/src/stream-to-bytes.js +30 -0
- package/dist/src/stream-to-bytes.js.map +1 -0
- package/dist/src/test/fixtures.d.ts +36 -0
- package/dist/src/test/fixtures.d.ts.map +1 -0
- package/dist/src/test/fixtures.js +172 -0
- package/dist/src/test/fixtures.js.map +1 -0
- package/dist/src/throttle.d.ts +25 -0
- package/dist/src/throttle.d.ts.map +1 -0
- package/dist/src/throttle.js +34 -0
- package/dist/src/throttle.js.map +1 -0
- package/dist/src/tile.d.ts +34 -0
- package/dist/src/tile.d.ts.map +1 -0
- package/dist/src/tile.js +72 -0
- package/dist/src/tile.js.map +1 -0
- package/dist/src/transform-bytes.d.ts +24 -0
- package/dist/src/transform-bytes.d.ts.map +1 -0
- package/dist/src/transform-bytes.js +28 -0
- package/dist/src/transform-bytes.js.map +1 -0
- package/dist/src/types.d.ts +99 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +9 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +30 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +70 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/way-is-area.d.ts +24 -0
- package/dist/src/way-is-area.d.ts.map +1 -0
- package/dist/src/way-is-area.js +104 -0
- package/dist/src/way-is-area.js.map +1 -0
- package/dist/src/zigzag.d.ts +33 -0
- package/dist/src/zigzag.d.ts.map +1 -0
- package/dist/src/zigzag.js +40 -0
- package/dist/src/zigzag.js.map +1 -0
- package/dist/test/haversine-distance.test.d.ts +2 -0
- package/dist/test/haversine-distance.test.d.ts.map +1 -0
- package/dist/test/haversine-distance.test.js +8 -0
- package/dist/test/haversine-distance.test.js.map +1 -0
- package/dist/test/relation-kind.test.d.ts +2 -0
- package/dist/test/relation-kind.test.d.ts.map +1 -0
- package/dist/test/relation-kind.test.js +367 -0
- package/dist/test/relation-kind.test.js.map +1 -0
- package/dist/test/relation-multipolygon.test.d.ts +2 -0
- package/dist/test/relation-multipolygon.test.d.ts.map +1 -0
- package/dist/test/relation-multipolygon.test.js +237 -0
- package/dist/test/relation-multipolygon.test.js.map +1 -0
- package/dist/test/utils.test.d.ts +2 -0
- package/dist/test/utils.test.d.ts.map +1 -0
- package/dist/test/utils.test.js +76 -0
- package/dist/test/utils.test.js.map +1 -0
- package/dist/test/way-is-area.test.d.ts +2 -0
- package/dist/test/way-is-area.test.d.ts.map +1 -0
- package/dist/test/way-is-area.test.js +31 -0
- package/dist/test/way-is-area.test.js.map +1 -0
- package/package.json +9 -7
- package/src/assert.ts +21 -1
- package/src/bbox-intersects.ts +30 -0
- package/src/bytes-to-stream.ts +17 -0
- package/src/coordinates.ts +45 -0
- package/src/haversine-distance.ts +10 -1
- package/src/progress.ts +55 -0
- package/src/relation-kind.ts +446 -0
- package/src/relation-multipolygon.ts +225 -0
- package/src/stream-to-bytes.ts +17 -0
- package/src/test/fixtures.ts +18 -14
- package/src/throttle.ts +37 -0
- package/src/tile.ts +89 -0
- package/src/transform-bytes.ts +23 -0
- package/src/types.ts +93 -1
- package/src/utils.ts +79 -0
- package/src/way-is-area.ts +107 -0
- package/src/zigzag.ts +42 -0
- package/test/haversine-distance.test.ts +2 -2
- package/test/relation-kind.test.ts +426 -0
- package/test/relation-multipolygon.test.ts +265 -0
- package/test/utils.test.ts +103 -0
- package/test/way-is-area.test.ts +42 -0
- package/tsconfig/base.json +2 -0
- package/tsconfig/test.json +1 -0
- package/src/spherical-mercator.test.ts +0 -42
- package/src/spherical-mercator.ts +0 -42
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream to byte array conversion.
|
|
3
|
+
*
|
|
4
|
+
* Consumes a ReadableStream and concatenates all chunks into a single Uint8Array.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { concatBytes } from "./concat-bytes";
|
|
9
|
+
/**
|
|
10
|
+
* Consume a ReadableStream and return all data as a single Uint8Array.
|
|
11
|
+
*
|
|
12
|
+
* Reads all chunks from the stream and concatenates them.
|
|
13
|
+
* The stream will be fully consumed after this function returns.
|
|
14
|
+
*
|
|
15
|
+
* @param stream - The stream to consume.
|
|
16
|
+
* @returns A Promise resolving to the concatenated bytes.
|
|
17
|
+
*/
|
|
18
|
+
export async function streamToBytes(stream) {
|
|
19
|
+
const reader = stream.getReader();
|
|
20
|
+
const chunks = [];
|
|
21
|
+
while (true) {
|
|
22
|
+
const { done, value } = await reader.read();
|
|
23
|
+
if (done) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
chunks.push(value);
|
|
27
|
+
}
|
|
28
|
+
return concatBytes(chunks);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=stream-to-bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-to-bytes.js","sourceRoot":"","sources":["../../src/stream-to-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,MAA+C;IAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IACjC,MAAM,MAAM,GAA8B,EAAE,CAAA;IAE5C,OAAO,IAAI,EAAE,CAAC;QACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAE3C,IAAI,IAAI,EAAE,CAAC;YACV,MAAK;QACN,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare function getFixturePath(url: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Get file from the cache folder or download it from the URL
|
|
4
|
+
*/
|
|
5
|
+
export declare function getFixtureFile(url: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
6
|
+
export declare function getFixtureFileReadStream(url: string): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
7
|
+
export declare function getFixtureFileWriteStream(url: string): WritableStream<Uint8Array<ArrayBufferLike>>;
|
|
8
|
+
export type PbfFixture = {
|
|
9
|
+
url: string;
|
|
10
|
+
bbox: {
|
|
11
|
+
bottom: number;
|
|
12
|
+
top: number;
|
|
13
|
+
left: number;
|
|
14
|
+
right: number;
|
|
15
|
+
};
|
|
16
|
+
nodesWithTags: number;
|
|
17
|
+
nodes: number;
|
|
18
|
+
ways: number;
|
|
19
|
+
relations: number;
|
|
20
|
+
node0: {
|
|
21
|
+
lat: number;
|
|
22
|
+
lon: number;
|
|
23
|
+
id: number;
|
|
24
|
+
};
|
|
25
|
+
way0: number;
|
|
26
|
+
relation0: number;
|
|
27
|
+
uniqueStrings: number;
|
|
28
|
+
primitiveGroups: number;
|
|
29
|
+
};
|
|
30
|
+
export declare const AllPBFs: Record<string, PbfFixture>;
|
|
31
|
+
/**
|
|
32
|
+
* A subset of the PBFs that we want to use for current tests. Do not check in changes to this list as it will cause CI to
|
|
33
|
+
* attempt to download PBFs that are not checked into the repository.
|
|
34
|
+
*/
|
|
35
|
+
export declare const PBFs: Record<string, PbfFixture>;
|
|
36
|
+
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"AAOA,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,UAOzC;AAED;;GAEG;AACH,wBAAsB,cAAc,CACnC,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAYtC;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,2CAEnD;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,+CAUpD;AAED,MAAM,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE;QACL,MAAM,EAAE,MAAM,CAAA;QACd,GAAG,EAAE,MAAM,CAAA;QACX,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAA;KACb,CAAA;IACD,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE;QACN,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;QACX,EAAE,EAAE,MAAM,CAAA;KACV,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;CACvB,CAAA;AAiCD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CA0FrC,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAgC,CAAA"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { dirname, join, resolve } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
4
|
+
const ROOT_DIR = resolve(__dirname, "../../../../");
|
|
5
|
+
const FIXTURES_DIR = resolve(ROOT_DIR, "fixtures");
|
|
6
|
+
export function getFixturePath(url) {
|
|
7
|
+
if (url.startsWith("http")) {
|
|
8
|
+
const fileName = url.split("/").pop();
|
|
9
|
+
if (!fileName)
|
|
10
|
+
throw new Error("Invalid URL");
|
|
11
|
+
return join(FIXTURES_DIR, fileName);
|
|
12
|
+
}
|
|
13
|
+
return join(FIXTURES_DIR, url);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get file from the cache folder or download it from the URL
|
|
17
|
+
*/
|
|
18
|
+
export async function getFixtureFile(url) {
|
|
19
|
+
const filePath = getFixturePath(url);
|
|
20
|
+
try {
|
|
21
|
+
const file = await Bun.file(filePath).arrayBuffer();
|
|
22
|
+
return new Uint8Array(file);
|
|
23
|
+
}
|
|
24
|
+
catch (_error) {
|
|
25
|
+
const response = await fetch(url);
|
|
26
|
+
const buffer = await response.arrayBuffer();
|
|
27
|
+
const data = new Uint8Array(buffer);
|
|
28
|
+
await Bun.write(filePath, data);
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function getFixtureFileReadStream(url) {
|
|
33
|
+
return Bun.file(getFixturePath(url)).stream();
|
|
34
|
+
}
|
|
35
|
+
export function getFixtureFileWriteStream(url) {
|
|
36
|
+
const incrementalWriter = Bun.file(getFixturePath(url)).writer();
|
|
37
|
+
return new WritableStream({
|
|
38
|
+
write: (chunk) => {
|
|
39
|
+
incrementalWriter.write(chunk);
|
|
40
|
+
},
|
|
41
|
+
close: () => {
|
|
42
|
+
incrementalWriter.end();
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* List of PBFs and their metadata used for testing. Cached locally in the top level fixtures directory so they can
|
|
48
|
+
* be used across packages and apps.
|
|
49
|
+
*
|
|
50
|
+
* `monaco.pbf` is checked into the repository so it can be used in CI without causing repeated downloads.
|
|
51
|
+
*
|
|
52
|
+
* Below, we export a subset of the PBFs that we want to use for current tests.
|
|
53
|
+
*/
|
|
54
|
+
const monacoPbfFixture = {
|
|
55
|
+
url: "monaco.pbf",
|
|
56
|
+
bbox: {
|
|
57
|
+
bottom: 43.7232244,
|
|
58
|
+
top: 43.7543687,
|
|
59
|
+
left: 7.4053929,
|
|
60
|
+
right: 7.4447259,
|
|
61
|
+
},
|
|
62
|
+
nodesWithTags: 1_254,
|
|
63
|
+
nodes: 14_286,
|
|
64
|
+
ways: 3_346,
|
|
65
|
+
relations: 46,
|
|
66
|
+
node0: {
|
|
67
|
+
lat: 43.7371175,
|
|
68
|
+
lon: 7.4229093,
|
|
69
|
+
id: 21911883,
|
|
70
|
+
},
|
|
71
|
+
way0: 4097656,
|
|
72
|
+
relation0: 3410831,
|
|
73
|
+
uniqueStrings: 1_060,
|
|
74
|
+
primitiveGroups: 7,
|
|
75
|
+
};
|
|
76
|
+
export const AllPBFs = {
|
|
77
|
+
monaco: monacoPbfFixture,
|
|
78
|
+
montenegro: {
|
|
79
|
+
url: "https://download.geofabrik.de/europe/montenegro-250101.osm.pbf",
|
|
80
|
+
bbox: {
|
|
81
|
+
bottom: 41.61621,
|
|
82
|
+
top: 43.562169,
|
|
83
|
+
left: 18.17282,
|
|
84
|
+
right: 20.358827,
|
|
85
|
+
},
|
|
86
|
+
nodesWithTags: 63_321,
|
|
87
|
+
nodes: 3_915_383,
|
|
88
|
+
ways: 321_330,
|
|
89
|
+
relations: 5_501,
|
|
90
|
+
node0: {
|
|
91
|
+
lat: 42.1982436,
|
|
92
|
+
lon: 18.9656482,
|
|
93
|
+
id: 26860768,
|
|
94
|
+
},
|
|
95
|
+
way0: 123,
|
|
96
|
+
relation0: 123,
|
|
97
|
+
uniqueStrings: 55_071,
|
|
98
|
+
primitiveGroups: 532,
|
|
99
|
+
},
|
|
100
|
+
croatia: {
|
|
101
|
+
url: "https://download.geofabrik.de/europe/croatia-250101.osm.pbf",
|
|
102
|
+
bbox: {
|
|
103
|
+
bottom: 42.16483,
|
|
104
|
+
top: 46.557562,
|
|
105
|
+
left: 13.08916,
|
|
106
|
+
right: 19.459968,
|
|
107
|
+
},
|
|
108
|
+
nodesWithTags: 481_613,
|
|
109
|
+
nodes: 23_063_621,
|
|
110
|
+
ways: 2_315_247,
|
|
111
|
+
relations: 39_098,
|
|
112
|
+
primitiveGroups: 3_178,
|
|
113
|
+
node0: {
|
|
114
|
+
lat: 42.9738772,
|
|
115
|
+
lon: 17.021989,
|
|
116
|
+
id: 4_511_653,
|
|
117
|
+
},
|
|
118
|
+
way0: 123,
|
|
119
|
+
relation0: 123,
|
|
120
|
+
uniqueStrings: 269_315,
|
|
121
|
+
},
|
|
122
|
+
italy: {
|
|
123
|
+
url: "https://download.geofabrik.de/europe/italy-250101.osm.pbf",
|
|
124
|
+
bbox: {
|
|
125
|
+
bottom: 35.07638,
|
|
126
|
+
left: 6.602696,
|
|
127
|
+
right: 19.12499,
|
|
128
|
+
top: 47.100045,
|
|
129
|
+
},
|
|
130
|
+
nodesWithTags: 1_513_303,
|
|
131
|
+
nodes: 250_818_620,
|
|
132
|
+
ways: 27_837_987,
|
|
133
|
+
relations: 100_000,
|
|
134
|
+
primitiveGroups: 34_901,
|
|
135
|
+
node0: {
|
|
136
|
+
lat: 41.9033,
|
|
137
|
+
lon: 12.4534,
|
|
138
|
+
id: 1,
|
|
139
|
+
},
|
|
140
|
+
way0: 123,
|
|
141
|
+
relation0: 123,
|
|
142
|
+
uniqueStrings: 3190,
|
|
143
|
+
},
|
|
144
|
+
washington: {
|
|
145
|
+
url: "https://download.geofabrik.de/north-america/us/washington-250101.osm.pbf",
|
|
146
|
+
bbox: {
|
|
147
|
+
bottom: 45.53882,
|
|
148
|
+
top: 49.00708,
|
|
149
|
+
left: -126.7423,
|
|
150
|
+
right: -116.911526,
|
|
151
|
+
},
|
|
152
|
+
nodesWithTags: 1_513_303,
|
|
153
|
+
nodes: 43_032_447,
|
|
154
|
+
ways: 4_541_651,
|
|
155
|
+
relations: 44_373,
|
|
156
|
+
node0: {
|
|
157
|
+
lat: 47.64248,
|
|
158
|
+
lon: -122.3196898,
|
|
159
|
+
id: 29445653,
|
|
160
|
+
},
|
|
161
|
+
way0: 123,
|
|
162
|
+
relation0: 123,
|
|
163
|
+
uniqueStrings: 598_993,
|
|
164
|
+
primitiveGroups: 34_901,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* A subset of the PBFs that we want to use for current tests. Do not check in changes to this list as it will cause CI to
|
|
169
|
+
* attempt to download PBFs that are not checked into the repository.
|
|
170
|
+
*/
|
|
171
|
+
export const PBFs = { monaco: monacoPbfFixture };
|
|
172
|
+
//# sourceMappingURL=fixtures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;AACnD,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAElD,MAAM,UAAU,cAAc,CAAC,GAAW;IACzC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;QACrC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;QAC7C,OAAO,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;IACpC,CAAC;IACD,OAAO,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,GAAW;IAEX,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,MAAM,GAAG,CAA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YACL,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,QAAQ;YACf,GAAG,EAAE,SAAS;SACd;QACD,aAAa,EAAE,SAAS;QACxB,KAAK,EAAE,WAAW;QAClB,IAAI,EAAE,UAAU;QAChB,SAAS,EAAE,OAAO;QAClB,eAAe,EAAE,MAAM;QACvB,KAAK,EAAE;YACN,GAAG,EAAE,OAAO;YACZ,GAAG,EAAE,OAAO;YACZ,EAAE,EAAE,CAAC;SACL;QACD,IAAI,EAAE,GAAG;QACT,SAAS,EAAE,GAAG;QACd,aAAa,EAAE,IAAI;KACnB;IACD,UAAU,EAAE;QACX,GAAG,EAAE,0EAA0E;QAC/E,IAAI,EAAE;YACL,MAAM,EAAE,QAAQ;YAChB,GAAG,EAAE,QAAQ;YACb,IAAI,EAAE,CAAC,QAAQ;YACf,KAAK,EAAE,CAAC,UAAU;SAClB;QACD,aAAa,EAAE,SAAS;QACxB,KAAK,EAAE,UAAU;QACjB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE;YACN,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,CAAC,WAAW;YACjB,EAAE,EAAE,QAAQ;SACZ;QACD,IAAI,EAAE,GAAG;QACT,SAAS,EAAE,GAAG;QACd,aAAa,EAAE,OAAO;QACtB,eAAe,EAAE,MAAM;KACvB;CACQ,CAAA;AAEV;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAA+B,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throttling utilities for rate-limiting function calls.
|
|
3
|
+
*
|
|
4
|
+
* Useful for limiting progress updates from workers or other high-frequency
|
|
5
|
+
* operations to avoid overwhelming the UI or logging.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Create a throttled version of a function that only executes at most
|
|
11
|
+
* once per `timeFrame` milliseconds.
|
|
12
|
+
*
|
|
13
|
+
* @param func - The function to throttle.
|
|
14
|
+
* @param timeFrame - Minimum time between calls in milliseconds.
|
|
15
|
+
* @returns A throttled version of the function.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const logThrottled = throttle((msg) => console.log(msg), 1000)
|
|
20
|
+
* // Only logs at most once per second
|
|
21
|
+
* for (let i = 0; i < 1000; i++) logThrottled(`Progress: ${i}`)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function throttle<T extends unknown[]>(func: (...args: T) => void, timeFrame: number): (...args: T) => void;
|
|
25
|
+
//# sourceMappingURL=throttle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../src/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAC3C,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,EAC1B,SAAS,EAAE,MAAM,IAGT,GAAG,MAAM,CAAC,UAOlB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throttling utilities for rate-limiting function calls.
|
|
3
|
+
*
|
|
4
|
+
* Useful for limiting progress updates from workers or other high-frequency
|
|
5
|
+
* operations to avoid overwhelming the UI or logging.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Create a throttled version of a function that only executes at most
|
|
11
|
+
* once per `timeFrame` milliseconds.
|
|
12
|
+
*
|
|
13
|
+
* @param func - The function to throttle.
|
|
14
|
+
* @param timeFrame - Minimum time between calls in milliseconds.
|
|
15
|
+
* @returns A throttled version of the function.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const logThrottled = throttle((msg) => console.log(msg), 1000)
|
|
20
|
+
* // Only logs at most once per second
|
|
21
|
+
* for (let i = 0; i < 1000; i++) logThrottled(`Progress: ${i}`)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function throttle(func, timeFrame) {
|
|
25
|
+
let lastTime = 0;
|
|
26
|
+
return (...args) => {
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
if (now - lastTime >= timeFrame) {
|
|
29
|
+
func(...args);
|
|
30
|
+
lastTime = now;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=throttle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../src/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CACvB,IAA0B,EAC1B,SAAiB;IAEjB,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,GAAG,IAAO,EAAE,EAAE;QACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,GAAG,GAAG,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;YACb,QAAQ,GAAG,GAAG,CAAA;QACf,CAAC;IACF,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XYZ tile coordinate utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides conversions between geographic coordinates (lon/lat) and
|
|
5
|
+
* tile pixel coordinates for XYZ tiled map systems. Supports various
|
|
6
|
+
* tile sizes and zoom levels.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { GeoBbox2D, LonLat, Tile, TilePxBbox, XY } from "./types";
|
|
11
|
+
/**
|
|
12
|
+
* Get the geographic bounding box of a tile.
|
|
13
|
+
* Returns [west, south, east, north].
|
|
14
|
+
*/
|
|
15
|
+
export declare function tileToBbox(tile: Tile): GeoBbox2D;
|
|
16
|
+
/**
|
|
17
|
+
* Convert a bounding box from geographic coordinates to tile pixel coordinates.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bboxToTilePx(bbox: GeoBbox2D, tile: Tile, tileSize?: number): TilePxBbox;
|
|
20
|
+
/**
|
|
21
|
+
* Convert a geographic coordinate to tile pixel coordinates.
|
|
22
|
+
* Returns [x, y] in pixels relative to the top-left of the tile.
|
|
23
|
+
*/
|
|
24
|
+
export declare function llToTilePx(ll: LonLat, tile: Tile, tileSize?: number): XY;
|
|
25
|
+
/**
|
|
26
|
+
* Convert tile pixel coordinates to geographic coordinates.
|
|
27
|
+
*/
|
|
28
|
+
export declare function tilePxToLonLat(px: XY, tile: Tile, tileSize?: number): LonLat;
|
|
29
|
+
/**
|
|
30
|
+
* Clamp a pixel coordinate to the tile bounds and round to the nearest integer. Useful for converting a floating point pixel
|
|
31
|
+
* coordinate to a the exact tile pixel it is contained by.
|
|
32
|
+
*/
|
|
33
|
+
export declare function clampAndRoundPx(px: XY, tileSizeOrBbox: number | GeoBbox2D): XY;
|
|
34
|
+
//# sourceMappingURL=tile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../src/tile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAatE;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAOhD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,IAAI,EACV,QAAQ,SAAM,GACZ,UAAU,CAIZ;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,SAAM,GAAG,EAAE,CAMrE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,SAAM,GAAG,MAAM,CAKzE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,EAAE,EAAE,EAAE,EACN,cAAc,EAAE,MAAM,GAAG,SAAS,GAChC,EAAE,CASJ"}
|
package/dist/src/tile.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XYZ tile coordinate utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides conversions between geographic coordinates (lon/lat) and
|
|
5
|
+
* tile pixel coordinates for XYZ tiled map systems. Supports various
|
|
6
|
+
* tile sizes and zoom levels.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { pointToTileFraction } from "@mapbox/tilebelt";
|
|
11
|
+
const RADIANS_TO_DEGREES = 180 / Math.PI;
|
|
12
|
+
function tile2lon(x, z) {
|
|
13
|
+
return (x / 2 ** z) * 360 - 180;
|
|
14
|
+
}
|
|
15
|
+
function tile2lat(y, z) {
|
|
16
|
+
const n = Math.PI - (2 * Math.PI * y) / 2 ** z;
|
|
17
|
+
return RADIANS_TO_DEGREES * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the geographic bounding box of a tile.
|
|
21
|
+
* Returns [west, south, east, north].
|
|
22
|
+
*/
|
|
23
|
+
export function tileToBbox(tile) {
|
|
24
|
+
const [tx, ty, tz] = tile;
|
|
25
|
+
const n = tile2lat(ty, tz);
|
|
26
|
+
const s = tile2lat(ty + 1, tz);
|
|
27
|
+
const e = tile2lon(tx + 1, tz);
|
|
28
|
+
const w = tile2lon(tx, tz);
|
|
29
|
+
return [w, s, e, n];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert a bounding box from geographic coordinates to tile pixel coordinates.
|
|
33
|
+
*/
|
|
34
|
+
export function bboxToTilePx(bbox, tile, tileSize = 256) {
|
|
35
|
+
const [minX, minY] = llToTilePx([bbox[0], bbox[3]], tile, tileSize);
|
|
36
|
+
const [maxX, maxY] = llToTilePx([bbox[2], bbox[1]], tile, tileSize);
|
|
37
|
+
return [minX, minY, maxX, maxY];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convert a geographic coordinate to tile pixel coordinates.
|
|
41
|
+
* Returns [x, y] in pixels relative to the top-left of the tile.
|
|
42
|
+
*/
|
|
43
|
+
export function llToTilePx(ll, tile, tileSize = 256) {
|
|
44
|
+
const [tx, ty, tz] = tile;
|
|
45
|
+
const tf = pointToTileFraction(ll[0], ll[1], tz);
|
|
46
|
+
const x = (tf[0] - tx) * tileSize;
|
|
47
|
+
const y = (tf[1] - ty) * tileSize;
|
|
48
|
+
return [x, y];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Convert tile pixel coordinates to geographic coordinates.
|
|
52
|
+
*/
|
|
53
|
+
export function tilePxToLonLat(px, tile, tileSize = 256) {
|
|
54
|
+
const [tx, ty, tz] = tile;
|
|
55
|
+
const lon = tile2lon(px[0] / tileSize + tx, tz);
|
|
56
|
+
const lat = tile2lat(px[1] / tileSize + ty, tz);
|
|
57
|
+
return [lon, lat];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Clamp a pixel coordinate to the tile bounds and round to the nearest integer. Useful for converting a floating point pixel
|
|
61
|
+
* coordinate to a the exact tile pixel it is contained by.
|
|
62
|
+
*/
|
|
63
|
+
export function clampAndRoundPx(px, tileSizeOrBbox) {
|
|
64
|
+
const [minX, minY, maxX, maxY] = typeof tileSizeOrBbox === "number"
|
|
65
|
+
? [0, 0, tileSizeOrBbox, tileSizeOrBbox]
|
|
66
|
+
: tileSizeOrBbox;
|
|
67
|
+
return [
|
|
68
|
+
Math.max(minX, Math.min(maxX, Math.round(px[0]))),
|
|
69
|
+
Math.max(minY, Math.min(maxY, Math.round(px[1]))),
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=tile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile.js","sourceRoot":"","sources":["../../src/tile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAGtD,MAAM,kBAAkB,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAA;AAExC,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACrC,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAA;AAChC,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACrC,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC9C,OAAO,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAAU;IACpC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAA;IACzB,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;IAC1B,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;IAC9B,MAAM,CAAC,GAAG,QAAQ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MAAM,UAAU,cAAc,CAAC,EAAM,EAAE,IAAU,EAAE,QAAQ,GAAG,GAAG;IAChE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAA;IACzB,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,CAAA;IAC/C,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,CAAA;IAC/C,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,EAAM,EACN,cAAkC;IAElC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,GAC7B,OAAO,cAAc,KAAK,QAAQ;QACjC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC;QACxC,CAAC,CAAC,cAAc,CAAA;IAClB,OAAO;QACN,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACjD,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform stream utilities.
|
|
3
|
+
*
|
|
4
|
+
* Helpers for piping byte arrays through TransformStreams (e.g., compression).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Pipe a byte array through a TransformStream and return the result.
|
|
10
|
+
*
|
|
11
|
+
* Useful for applying compression/decompression or other transformations
|
|
12
|
+
* to byte data using the Web Streams API.
|
|
13
|
+
*
|
|
14
|
+
* @param bytes - The input bytes.
|
|
15
|
+
* @param transformStream - The transform to apply (e.g., CompressionStream).
|
|
16
|
+
* @returns A Promise resolving to the transformed bytes.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const compressed = await transformBytes(data, new CompressionStream('gzip'))
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function transformBytes(bytes: Uint8Array<ArrayBuffer>, transformStream: TransformStream<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
|
|
24
|
+
//# sourceMappingURL=transform-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-bytes.d.ts","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CACnC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAC9B,eAAe,EAAE,eAAe,CAC/B,UAAU,CAAC,WAAW,CAAC,EACvB,UAAU,CAAC,WAAW,CAAC,CACvB,GACC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform stream utilities.
|
|
3
|
+
*
|
|
4
|
+
* Helpers for piping byte arrays through TransformStreams (e.g., compression).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { bytesToStream } from "./bytes-to-stream";
|
|
9
|
+
import { streamToBytes } from "./stream-to-bytes";
|
|
10
|
+
/**
|
|
11
|
+
* Pipe a byte array through a TransformStream and return the result.
|
|
12
|
+
*
|
|
13
|
+
* Useful for applying compression/decompression or other transformations
|
|
14
|
+
* to byte data using the Web Streams API.
|
|
15
|
+
*
|
|
16
|
+
* @param bytes - The input bytes.
|
|
17
|
+
* @param transformStream - The transform to apply (e.g., CompressionStream).
|
|
18
|
+
* @returns A Promise resolving to the transformed bytes.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const compressed = await transformBytes(data, new CompressionStream('gzip'))
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export async function transformBytes(bytes, transformStream) {
|
|
26
|
+
return streamToBytes(bytesToStream(bytes).pipeThrough(transformStream));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=transform-bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-bytes.js","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAA8B,EAC9B,eAGC;IAED,OAAO,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions used across all Osmix packages.
|
|
3
|
+
*
|
|
4
|
+
* Includes geographic primitives (LonLat, Bbox), tile coordinates,
|
|
5
|
+
* and core OSM entity types (Node, Way, Relation).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Geographic coordinate as [longitude, latitude] tuple. */
|
|
10
|
+
export type LonLat = [lon: number, lat: number];
|
|
11
|
+
/** 2D pixel or cartesian coordinate as [x, y] tuple. */
|
|
12
|
+
export type XY = [x: number, y: number];
|
|
13
|
+
/** Geographic coordinate as object with lon/lat properties. */
|
|
14
|
+
export interface ILonLat {
|
|
15
|
+
lon: number;
|
|
16
|
+
lat: number;
|
|
17
|
+
}
|
|
18
|
+
/** XYZ tile coordinate as [x, y, z] tuple. */
|
|
19
|
+
export type Tile = [x: number, y: number, z: number];
|
|
20
|
+
/**
|
|
21
|
+
* Project LonLat to pixels
|
|
22
|
+
*/
|
|
23
|
+
export type LonLatToPixel = (ll: LonLat, zoom: number) => XY;
|
|
24
|
+
export type LonLatToTilePixel = (ll: LonLat, z: number, extent: number) => XY;
|
|
25
|
+
export type Rgba = [r: number, g: number, b: number, a: number] | Uint8ClampedArray;
|
|
26
|
+
/**
|
|
27
|
+
* A bounding box in the format [minLon, minLat, maxLon, maxLat].
|
|
28
|
+
* GeoJSON.BBox allows for 3D bounding boxes, but we use tools that expect 2D bounding boxes.
|
|
29
|
+
*/
|
|
30
|
+
export type GeoBbox2D = [
|
|
31
|
+
minLon: number,
|
|
32
|
+
minLat: number,
|
|
33
|
+
maxLon: number,
|
|
34
|
+
maxLat: number
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* A pixel bounding box in the format [minX, minY, maxX, maxY]. Note: minY is north. maxY is south.
|
|
38
|
+
*/
|
|
39
|
+
export type TilePxBbox = [
|
|
40
|
+
minX: number,
|
|
41
|
+
minY: number,
|
|
42
|
+
maxX: number,
|
|
43
|
+
maxY: number
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Shared OSM Types
|
|
47
|
+
*/
|
|
48
|
+
export type OsmEntityType = "node" | "way" | "relation";
|
|
49
|
+
export interface OsmInfoParsed {
|
|
50
|
+
version?: number;
|
|
51
|
+
timestamp?: number;
|
|
52
|
+
changeset?: number;
|
|
53
|
+
uid?: number;
|
|
54
|
+
user_sid?: number;
|
|
55
|
+
visible?: boolean;
|
|
56
|
+
user?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface OsmTags {
|
|
59
|
+
[key: string]: string | number;
|
|
60
|
+
}
|
|
61
|
+
interface IOsmEntity {
|
|
62
|
+
id: number;
|
|
63
|
+
info?: OsmInfoParsed;
|
|
64
|
+
tags?: OsmTags;
|
|
65
|
+
}
|
|
66
|
+
export interface OsmNode extends IOsmEntity, ILonLat {
|
|
67
|
+
}
|
|
68
|
+
export interface OsmWay extends IOsmEntity {
|
|
69
|
+
refs: number[];
|
|
70
|
+
}
|
|
71
|
+
export interface OsmRelationMember {
|
|
72
|
+
type: OsmEntityType;
|
|
73
|
+
ref: number;
|
|
74
|
+
role?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface OsmRelation extends IOsmEntity {
|
|
77
|
+
members: OsmRelationMember[];
|
|
78
|
+
}
|
|
79
|
+
export type OsmEntity = OsmNode | OsmWay | OsmRelation;
|
|
80
|
+
export interface OsmEntityTypeMap extends Record<OsmEntityType, IOsmEntity> {
|
|
81
|
+
node: OsmNode;
|
|
82
|
+
way: OsmWay;
|
|
83
|
+
relation: OsmRelation;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Semantic kinds of OSM relations based on their type tag and structure.
|
|
87
|
+
*/
|
|
88
|
+
export type RelationKind = "area" | "line" | "point" | "logic" | "super";
|
|
89
|
+
/**
|
|
90
|
+
* Metadata about a relation kind, including expected roles and whether member order matters.
|
|
91
|
+
*/
|
|
92
|
+
export interface RelationKindMetadata {
|
|
93
|
+
kind: RelationKind;
|
|
94
|
+
expectedRoles?: string[];
|
|
95
|
+
orderMatters: boolean;
|
|
96
|
+
description: string;
|
|
97
|
+
}
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,4DAA4D;AAC5D,MAAM,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AA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0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General OSM entity utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides type guards, equality checks, and type detection for OSM entities.
|
|
5
|
+
* Uses deep equality checking for tags, info, and entity-specific properties.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { OsmEntity, OsmEntityType, OsmNode, OsmRelation, OsmWay } from "./types";
|
|
10
|
+
/** Type guard: check if entity is a Node. */
|
|
11
|
+
export declare function isNode(entity: OsmEntity): entity is OsmNode;
|
|
12
|
+
/** Check if two nodes are equal (position, tags, and info). */
|
|
13
|
+
export declare function isNodeEqual(a: OsmNode, b: OsmNode): boolean;
|
|
14
|
+
/** Type guard: check if entity is a Way. */
|
|
15
|
+
export declare function isWay(entity: OsmEntity): entity is OsmWay;
|
|
16
|
+
/** Type guard: check if entity is a Relation. */
|
|
17
|
+
export declare function isRelation(entity: OsmEntity): entity is OsmRelation;
|
|
18
|
+
/** Check if two ways are equal (refs, tags, and info). */
|
|
19
|
+
export declare function isWayEqual(a: OsmWay, b: OsmWay): boolean;
|
|
20
|
+
/** Check if two relations are equal (members, tags, and info). */
|
|
21
|
+
export declare function isRelationEqual(a: OsmRelation, b: OsmRelation): boolean;
|
|
22
|
+
/** Check if two entities have equal properties (type-aware comparison). */
|
|
23
|
+
export declare function entityPropertiesEqual(a: OsmEntity, b: OsmEntity): boolean;
|
|
24
|
+
/** Get the entity type ("node", "way", or "relation") for an entity. */
|
|
25
|
+
export declare function getEntityType(entity: OsmEntity): OsmEntityType;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a relation is a multipolygon relation.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isMultipolygonRelation(relation: OsmRelation): boolean;
|
|
30
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,WAAW,EACX,MAAM,EACN,MAAM,SAAS,CAAA;AAShB,6CAA6C;AAC7C,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,OAAO,CAE3D;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,WAEjD;AAED,4CAA4C;AAC5C,wBAAgB,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,MAAM,CAEzD;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,WAAW,CAEnE;AAED,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,WAE9C;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,WAE7D;AAED,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,WAO/D;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa,CAK9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAErE"}
|