@osmix/shared 0.0.2 → 0.0.7
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/assert.d.ts +24 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +28 -0
- package/dist/assert.js.map +1 -0
- package/dist/bbox-intersects.d.ts +15 -0
- package/dist/bbox-intersects.d.ts.map +1 -0
- package/dist/bbox-intersects.js +24 -0
- package/dist/bbox-intersects.js.map +1 -0
- package/dist/bytes-to-stream.d.ts +18 -0
- package/dist/bytes-to-stream.d.ts.map +1 -0
- package/dist/bytes-to-stream.js +25 -0
- package/dist/bytes-to-stream.js.map +1 -0
- package/dist/color.d.ts +4 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +33 -0
- package/dist/color.js.map +1 -0
- package/dist/concat-bytes.d.ts +5 -0
- package/dist/concat-bytes.d.ts.map +1 -0
- package/dist/concat-bytes.js +14 -0
- package/dist/concat-bytes.js.map +1 -0
- package/dist/coordinates.d.ts +28 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +38 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/haversine-distance.d.ts +16 -0
- package/dist/haversine-distance.d.ts.map +1 -0
- package/dist/haversine-distance.js +26 -0
- package/dist/haversine-distance.js.map +1 -0
- package/dist/lineclip.d.ts +2 -0
- package/dist/lineclip.d.ts.map +1 -0
- package/dist/lineclip.js +3 -0
- package/dist/lineclip.js.map +1 -0
- package/dist/progress.d.ts +42 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +53 -0
- package/dist/progress.js.map +1 -0
- package/dist/relation-kind.d.ts +69 -0
- package/dist/relation-kind.d.ts.map +1 -0
- package/dist/relation-kind.js +375 -0
- package/dist/relation-kind.js.map +1 -0
- package/dist/relation-multipolygon.d.ts +43 -0
- package/dist/relation-multipolygon.d.ts.map +1 -0
- package/dist/relation-multipolygon.js +195 -0
- package/dist/relation-multipolygon.js.map +1 -0
- package/dist/src/assert.d.ts +20 -1
- package/dist/src/assert.d.ts.map +1 -1
- package/dist/src/assert.js +20 -1
- package/dist/src/assert.js.map +1 -1
- 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 +17 -1
- package/dist/src/bytes-to-stream.d.ts.map +1 -1
- package/dist/src/bytes-to-stream.js +16 -0
- package/dist/src/bytes-to-stream.js.map +1 -1
- package/dist/src/color.d.ts +4 -0
- package/dist/src/color.d.ts.map +1 -0
- package/dist/src/color.js +33 -0
- package/dist/src/color.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 +9 -1
- package/dist/src/haversine-distance.d.ts.map +1 -1
- package/dist/src/haversine-distance.js +9 -1
- package/dist/src/haversine-distance.js.map +1 -1
- package/dist/src/progress.d.ts +42 -0
- package/dist/src/progress.d.ts.map +1 -0
- package/dist/src/progress.js +53 -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 +16 -0
- package/dist/src/stream-to-bytes.d.ts.map +1 -1
- package/dist/src/stream-to-bytes.js +16 -0
- package/dist/src/stream-to-bytes.js.map +1 -1
- package/dist/src/test/fixtures.d.ts +1 -1
- package/dist/src/test/fixtures.d.ts.map +1 -1
- package/dist/src/test/fixtures.js +16 -8
- package/dist/src/test/fixtures.js.map +1 -1
- 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 +22 -0
- package/dist/src/transform-bytes.d.ts.map +1 -1
- package/dist/src/transform-bytes.js +22 -0
- package/dist/src/transform-bytes.js.map +1 -1
- package/dist/src/types.d.ts +76 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +8 -0
- package/dist/src/types.js.map +1 -1
- 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/stream-to-bytes.d.ts +18 -0
- package/dist/stream-to-bytes.d.ts.map +1 -0
- package/dist/stream-to-bytes.js +30 -0
- package/dist/stream-to-bytes.js.map +1 -0
- package/dist/test/fixtures.d.ts +36 -0
- package/dist/test/fixtures.d.ts.map +1 -0
- package/dist/test/fixtures.js +175 -0
- package/dist/test/fixtures.js.map +1 -0
- package/dist/test/haversine-distance.test.js +2 -2
- package/dist/test/haversine-distance.test.js.map +1 -1
- 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/dist/throttle.d.ts +25 -0
- package/dist/throttle.d.ts.map +1 -0
- package/dist/throttle.js +34 -0
- package/dist/throttle.js.map +1 -0
- package/dist/tile.d.ts +34 -0
- package/dist/tile.d.ts.map +1 -0
- package/dist/tile.js +72 -0
- package/dist/tile.js.map +1 -0
- package/dist/transform-bytes.d.ts +24 -0
- package/dist/transform-bytes.d.ts.map +1 -0
- package/dist/transform-bytes.js +28 -0
- package/dist/transform-bytes.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +30 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +70 -0
- package/dist/utils.js.map +1 -0
- package/dist/way-is-area.d.ts +24 -0
- package/dist/way-is-area.d.ts.map +1 -0
- package/dist/way-is-area.js +104 -0
- package/dist/way-is-area.js.map +1 -0
- package/dist/zigzag.d.ts +33 -0
- package/dist/zigzag.d.ts.map +1 -0
- package/dist/zigzag.js +40 -0
- package/dist/zigzag.js.map +1 -0
- package/package.json +11 -10
- package/src/assert.ts +21 -1
- package/src/bbox-intersects.ts +30 -0
- package/src/bytes-to-stream.ts +17 -0
- package/src/color.ts +37 -0
- package/src/coordinates.ts +45 -0
- package/src/haversine-distance.ts +10 -1
- package/src/progress.ts +74 -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 +16 -12
- 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/test.json +1 -0
- package/tsconfig.build.json +5 -0
- package/dist/src/spherical-mercator.d.ts +0 -15
- package/dist/src/spherical-mercator.d.ts.map +0 -1
- package/dist/src/spherical-mercator.js +0 -35
- package/dist/src/spherical-mercator.js.map +0 -1
- package/dist/src/spherical-mercator.test.d.ts +0 -2
- package/dist/src/spherical-mercator.test.d.ts.map +0 -1
- package/dist/src/spherical-mercator.test.js +0 -25
- package/dist/src/spherical-mercator.test.js.map +0 -1
- package/src/spherical-mercator.test.ts +0 -42
- package/src/spherical-mercator.ts +0 -42
package/dist/src/types.d.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
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. */
|
|
1
10
|
export type LonLat = [lon: number, lat: number];
|
|
11
|
+
/** 2D pixel or cartesian coordinate as [x, y] tuple. */
|
|
2
12
|
export type XY = [x: number, y: number];
|
|
13
|
+
/** Geographic coordinate as object with lon/lat properties. */
|
|
3
14
|
export interface ILonLat {
|
|
4
15
|
lon: number;
|
|
5
16
|
lat: number;
|
|
6
17
|
}
|
|
18
|
+
/** XYZ tile coordinate as [x, y, z] tuple. */
|
|
7
19
|
export type Tile = [x: number, y: number, z: number];
|
|
8
20
|
/**
|
|
9
21
|
* Project LonLat to pixels
|
|
10
22
|
*/
|
|
11
23
|
export type LonLatToPixel = (ll: LonLat, zoom: number) => XY;
|
|
12
24
|
export type LonLatToTilePixel = (ll: LonLat, z: number, extent: number) => XY;
|
|
13
|
-
export type Rgba = [number, number, number, number] | Uint8ClampedArray;
|
|
25
|
+
export type Rgba = [r: number, g: number, b: number, a: number] | Uint8ClampedArray;
|
|
14
26
|
/**
|
|
15
27
|
* A bounding box in the format [minLon, minLat, maxLon, maxLat].
|
|
16
28
|
* GeoJSON.BBox allows for 3D bounding boxes, but we use tools that expect 2D bounding boxes.
|
|
@@ -21,4 +33,67 @@ export type GeoBbox2D = [
|
|
|
21
33
|
maxLon: number,
|
|
22
34
|
maxLat: number
|
|
23
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 {};
|
|
24
99
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AAC/C,MAAM,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"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,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB,YAAY,EAAE,OAAO,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;CACnB"}
|
package/dist/src/types.js
CHANGED
package/dist/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
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"}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { dequal } from "dequal/lite";
|
|
10
|
+
/**
|
|
11
|
+
* Check if two entities have equal tags and info.
|
|
12
|
+
*/
|
|
13
|
+
function isTagsAndInfoEqual(a, b) {
|
|
14
|
+
return dequal(a.tags, b.tags) && dequal(a.info, b.info);
|
|
15
|
+
}
|
|
16
|
+
/** Type guard: check if entity is a Node. */
|
|
17
|
+
export function isNode(entity) {
|
|
18
|
+
return "lon" in entity && "lat" in entity;
|
|
19
|
+
}
|
|
20
|
+
/** Check if two nodes are equal (position, tags, and info). */
|
|
21
|
+
export function isNodeEqual(a, b) {
|
|
22
|
+
return a.lat === b.lat && a.lon === b.lon && isTagsAndInfoEqual(a, b);
|
|
23
|
+
}
|
|
24
|
+
/** Type guard: check if entity is a Way. */
|
|
25
|
+
export function isWay(entity) {
|
|
26
|
+
return "refs" in entity;
|
|
27
|
+
}
|
|
28
|
+
/** Type guard: check if entity is a Relation. */
|
|
29
|
+
export function isRelation(entity) {
|
|
30
|
+
return "members" in entity;
|
|
31
|
+
}
|
|
32
|
+
/** Check if two ways are equal (refs, tags, and info). */
|
|
33
|
+
export function isWayEqual(a, b) {
|
|
34
|
+
return dequal(a.refs, b.refs) && isTagsAndInfoEqual(a, b);
|
|
35
|
+
}
|
|
36
|
+
/** Check if two relations are equal (members, tags, and info). */
|
|
37
|
+
export function isRelationEqual(a, b) {
|
|
38
|
+
return dequal(a.members, b.members) && isTagsAndInfoEqual(a, b);
|
|
39
|
+
}
|
|
40
|
+
/** Check if two entities have equal properties (type-aware comparison). */
|
|
41
|
+
export function entityPropertiesEqual(a, b) {
|
|
42
|
+
if (!dequal(a.tags, b.tags))
|
|
43
|
+
return false;
|
|
44
|
+
if (!dequal(a.info, b.info))
|
|
45
|
+
return false;
|
|
46
|
+
if (isNode(a) && isNode(b))
|
|
47
|
+
return isNodeEqual(a, b);
|
|
48
|
+
if (isWay(a) && isWay(b))
|
|
49
|
+
return isWayEqual(a, b);
|
|
50
|
+
if (isRelation(a) && isRelation(b))
|
|
51
|
+
return isRelationEqual(a, b);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
/** Get the entity type ("node", "way", or "relation") for an entity. */
|
|
55
|
+
export function getEntityType(entity) {
|
|
56
|
+
if (isNode(entity))
|
|
57
|
+
return "node";
|
|
58
|
+
if (isWay(entity))
|
|
59
|
+
return "way";
|
|
60
|
+
if (isRelation(entity))
|
|
61
|
+
return "relation";
|
|
62
|
+
throw Error("Unknown entity type");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if a relation is a multipolygon relation.
|
|
66
|
+
*/
|
|
67
|
+
export function isMultipolygonRelation(relation) {
|
|
68
|
+
return relation.tags?.["type"] === "multipolygon";
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AASpC;;GAEG;AACH,SAAS,kBAAkB,CAAC,CAAY,EAAE,CAAY;IACrD,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;AACxD,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,MAAM,CAAC,MAAiB;IACvC,OAAO,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAA;AAC1C,CAAC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AK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACjD,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC;QAAE,OAAO,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAChE,OAAO,KAAK,CAAA;AACb,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAAC,MAAiB;IAC9C,IAAI,MAAM,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IACjC,IAAI,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/B,IAAI,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,UAAU,CAAA;IACzC,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAqB;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,cAAc,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Area detection for OSM ways.
|
|
3
|
+
*
|
|
4
|
+
* Implements the OSM wiki heuristics for determining whether a closed way
|
|
5
|
+
* should be rendered as an area (polygon) or a closed linear feature.
|
|
6
|
+
*
|
|
7
|
+
* @see https://wiki.openstreetmap.org/wiki/Key:area
|
|
8
|
+
* @see https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { OsmWay } from "./types";
|
|
13
|
+
/**
|
|
14
|
+
* Determine if a way is an area based on its tags and nodes.
|
|
15
|
+
*
|
|
16
|
+
* This function implements the logic described in the OSM wiki:
|
|
17
|
+
* https://wiki.openstreetmap.org/wiki/Key:area
|
|
18
|
+
* https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
19
|
+
*
|
|
20
|
+
* @param way - The way to check.
|
|
21
|
+
* @returns `true` if the way is an area, `false` otherwise.
|
|
22
|
+
*/
|
|
23
|
+
export declare function wayIsArea(way?: OsmWay): boolean;
|
|
24
|
+
//# sourceMappingURL=way-is-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"way-is-area.d.ts","sourceRoot":"","sources":["../../src/way-is-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAqDrC;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CA+B/C"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Area detection for OSM ways.
|
|
3
|
+
*
|
|
4
|
+
* Implements the OSM wiki heuristics for determining whether a closed way
|
|
5
|
+
* should be rendered as an area (polygon) or a closed linear feature.
|
|
6
|
+
*
|
|
7
|
+
* @see https://wiki.openstreetmap.org/wiki/Key:area
|
|
8
|
+
* @see https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Tags that imply an area unless their value is exactly "no"
|
|
14
|
+
*/
|
|
15
|
+
const IMPLIED_ANY_VALUE_BUT_NO = new Set([
|
|
16
|
+
"amenity",
|
|
17
|
+
"boundary",
|
|
18
|
+
"building",
|
|
19
|
+
"building:part",
|
|
20
|
+
"craft",
|
|
21
|
+
// "golf", Seeing a lot of golf=cartpath which is not an area
|
|
22
|
+
"historic",
|
|
23
|
+
"indoor",
|
|
24
|
+
"landuse",
|
|
25
|
+
"leisure",
|
|
26
|
+
"military",
|
|
27
|
+
"office",
|
|
28
|
+
"place",
|
|
29
|
+
"public_transport",
|
|
30
|
+
"ruins",
|
|
31
|
+
"shop",
|
|
32
|
+
"tourism",
|
|
33
|
+
]);
|
|
34
|
+
/**
|
|
35
|
+
* Tags that imply an area only for these specific values
|
|
36
|
+
*/
|
|
37
|
+
const INCLUDED_VALUE_TAGS = {
|
|
38
|
+
barrier: new Set([
|
|
39
|
+
"city_wall",
|
|
40
|
+
"ditch",
|
|
41
|
+
"hedge",
|
|
42
|
+
"retaining_wall",
|
|
43
|
+
"wall",
|
|
44
|
+
"spikes",
|
|
45
|
+
]),
|
|
46
|
+
highway: new Set(["services", "rest_area", "escape", "elevator"]),
|
|
47
|
+
power: new Set(["plant", "substation", "generator", "transformer"]),
|
|
48
|
+
railway: new Set(["station", "turntable", "roundhouse", "platform"]),
|
|
49
|
+
waterway: new Set(["riverbank", "dock", "boatyard", "dam"]),
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Tags that imply an area unless the value is in this exclusion list
|
|
53
|
+
*/
|
|
54
|
+
const EXCLUDED_VALUE_TAGS = {
|
|
55
|
+
aeroway: new Set(["no", "taxiway"]),
|
|
56
|
+
"area:highway": new Set(["no"]),
|
|
57
|
+
man_made: new Set(["no", "cutline", "embankment", "pipeline"]),
|
|
58
|
+
natural: new Set(["no", "coastline", "cliff", "ridge", "arete", "tree_row"]),
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Determine if a way is an area based on its tags and nodes.
|
|
62
|
+
*
|
|
63
|
+
* This function implements the logic described in the OSM wiki:
|
|
64
|
+
* https://wiki.openstreetmap.org/wiki/Key:area
|
|
65
|
+
* https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
|
|
66
|
+
*
|
|
67
|
+
* @param way - The way to check.
|
|
68
|
+
* @returns `true` if the way is an area, `false` otherwise.
|
|
69
|
+
*/
|
|
70
|
+
export function wayIsArea(way) {
|
|
71
|
+
if (!way)
|
|
72
|
+
return false;
|
|
73
|
+
const { refs, tags } = way;
|
|
74
|
+
if (refs.length < 3)
|
|
75
|
+
return false;
|
|
76
|
+
if (refs[0] !== refs[refs.length - 1])
|
|
77
|
+
return false;
|
|
78
|
+
// End refs are equal, no tags, assume it is an area.
|
|
79
|
+
if (!tags || Object.keys(tags).length === 0)
|
|
80
|
+
return true;
|
|
81
|
+
// Explicit override
|
|
82
|
+
if ("area" in tags)
|
|
83
|
+
return tags["area"] !== "no";
|
|
84
|
+
// Tags that count if value is NOT "no"
|
|
85
|
+
for (const key of IMPLIED_ANY_VALUE_BUT_NO) {
|
|
86
|
+
const v = tags[key];
|
|
87
|
+
if (v && v !== "no")
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
// Tags that are area only for INCLUDED values
|
|
91
|
+
for (const [key, included] of Object.entries(INCLUDED_VALUE_TAGS)) {
|
|
92
|
+
const v = tags[key];
|
|
93
|
+
if (v && included.has(`${v}`))
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
// Tags that are area unless value is excluded
|
|
97
|
+
for (const [key, excluded] of Object.entries(EXCLUDED_VALUE_TAGS)) {
|
|
98
|
+
const v = tags[key];
|
|
99
|
+
if (v && !excluded.has(`${v}`))
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=way-is-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"way-is-area.js","sourceRoot":"","sources":["../../src/way-is-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;GAEG;AACH,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACxC,SAAS;IACT,UAAU;IACV,UAAU;IACV,eAAe;IACf,OAAO;IACP,8DAA8D;IAC9D,UAAU;IACV,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,QAAQ;IACR,OAAO;IACP,kBAAkB;IAClB,OAAO;IACP,MAAM;IACN,SAAS;CACT,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC3B,OA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;QAAE,OAAO,KAAK,CAAA;IAEnD,qDAAqD;IACrD,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAExD,oBAAoB;IACpB,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;IAEhD,uCAAuC;IACvC,KAAK,MAAM,GAAG,IAAI,wBAAwB,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;IACjC,CAAC;IAED,8CAA8C;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,IAAI,CAAA;IAC3C,CAAC;IAED,8CAA8C;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,IAAI,CAAA;IAC5C,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zigzag encoding/decoding for protobuf-style varints.
|
|
3
|
+
*
|
|
4
|
+
* Zigzag encoding converts signed integers to unsigned by interleaving
|
|
5
|
+
* negative and positive values: 0, -1, 1, -2, 2, ... This allows efficient
|
|
6
|
+
* varint encoding of small negative numbers.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Zigzag encode a number using arithmetic operations.
|
|
12
|
+
* This supports the full safe integer range (up to Number.MAX_SAFE_INTEGER).
|
|
13
|
+
* Formula: n < 0 ? -2*n - 1 : 2*n
|
|
14
|
+
*
|
|
15
|
+
* Used for encoding IDs in vector tiles to convert negative IDs to positive numbers
|
|
16
|
+
* for unsigned varint encoding.
|
|
17
|
+
*/
|
|
18
|
+
export declare function zigzag(num: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Zigzag encode using bitwise operations (for geometry deltas only).
|
|
21
|
+
* This is faster but limited to 32-bit signed integers.
|
|
22
|
+
* Used for small coordinate deltas in geometry encoding.
|
|
23
|
+
*/
|
|
24
|
+
export declare function zigzag32(num: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Decode zigzag-encoded number back to original value.
|
|
27
|
+
* Zigzag encoding is used to convert negative IDs to positive numbers for unsigned varint
|
|
28
|
+
* encoding in vector tiles. Uses arithmetic-based decoding to support the full safe integer range.
|
|
29
|
+
*
|
|
30
|
+
* Formula: (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeZigzag(encoded: number): number;
|
|
33
|
+
//# sourceMappingURL=zigzag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zigzag.d.ts","sourceRoot":"","sources":["../../src/zigzag.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGpD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zigzag encoding/decoding for protobuf-style varints.
|
|
3
|
+
*
|
|
4
|
+
* Zigzag encoding converts signed integers to unsigned by interleaving
|
|
5
|
+
* negative and positive values: 0, -1, 1, -2, 2, ... This allows efficient
|
|
6
|
+
* varint encoding of small negative numbers.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Zigzag encode a number using arithmetic operations.
|
|
12
|
+
* This supports the full safe integer range (up to Number.MAX_SAFE_INTEGER).
|
|
13
|
+
* Formula: n < 0 ? -2*n - 1 : 2*n
|
|
14
|
+
*
|
|
15
|
+
* Used for encoding IDs in vector tiles to convert negative IDs to positive numbers
|
|
16
|
+
* for unsigned varint encoding.
|
|
17
|
+
*/
|
|
18
|
+
export function zigzag(num) {
|
|
19
|
+
return num < 0 ? -2 * num - 1 : 2 * num;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Zigzag encode using bitwise operations (for geometry deltas only).
|
|
23
|
+
* This is faster but limited to 32-bit signed integers.
|
|
24
|
+
* Used for small coordinate deltas in geometry encoding.
|
|
25
|
+
*/
|
|
26
|
+
export function zigzag32(num) {
|
|
27
|
+
return (num << 1) ^ (num >> 31);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decode zigzag-encoded number back to original value.
|
|
31
|
+
* Zigzag encoding is used to convert negative IDs to positive numbers for unsigned varint
|
|
32
|
+
* encoding in vector tiles. Uses arithmetic-based decoding to support the full safe integer range.
|
|
33
|
+
*
|
|
34
|
+
* Formula: (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2
|
|
35
|
+
*/
|
|
36
|
+
export function decodeZigzag(encoded) {
|
|
37
|
+
// Check if encoded is odd (negative) using bitwise, then use arithmetic
|
|
38
|
+
return (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=zigzag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zigzag.js","sourceRoot":"","sources":["../../src/zigzag.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IACjC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IACnC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;AAChC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC3C,wEAAwE;IACxE,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAA;AAC9D,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Consume a ReadableStream and return all data as a single Uint8Array.
|
|
10
|
+
*
|
|
11
|
+
* Reads all chunks from the stream and concatenates them.
|
|
12
|
+
* The stream will be fully consumed after this function returns.
|
|
13
|
+
*
|
|
14
|
+
* @param stream - The stream to consume.
|
|
15
|
+
* @returns A Promise resolving to the concatenated bytes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function streamToBytes(stream: ReadableStream<Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
|
|
18
|
+
//# sourceMappingURL=stream-to-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-to-bytes.d.ts","sourceRoot":"","sources":["../src/stream-to-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAClC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAC7C,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAelC"}
|
|
@@ -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,CAetC;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"}
|