@maplibre/mlt-wasm 0.1.41 → 0.1.44

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/README.md CHANGED
@@ -13,7 +13,8 @@ mlt-wasm/
13
13
  │ ├── index.ts # package entry point
14
14
  │ ├── wasm.ts # the one module that imports pkg/
15
15
  │ ├── annotate.ts # annotated-dump wire contract
16
- │ └── vectorTile.ts # VectorTileLike wrapper
16
+ │ ├── columns.ts # typed-array layers, as decoded
17
+ │ └── vectorTile.ts # VectorTileLike wrapper over columns.ts
17
18
  ├── pkg/ # wasm-pack output (gitignored)
18
19
  ├── dist/ # tsc output (gitignored)
19
20
  ├── Cargo.toml
@@ -36,7 +37,8 @@ npm run build:wasm
36
37
  npm run build:ts
37
38
  ```
38
39
 
39
- `decodeTile` skips v2 layers unless the wasm is built with the `unstable-v2` feature, as `npm run build:test` does.
40
+ The `unstable-v2` feature is on by default, so v2 layers decode. Building with
41
+ `--no-default-features` skips them.
40
42
 
41
43
  ## Usage
42
44
 
@@ -51,22 +53,139 @@ for (const [name, layer] of Object.entries(tile.layers)) {
51
53
  const feature = layer.feature(i);
52
54
  console.log(feature.type); // 1 | 2 | 3
53
55
  console.log(feature.id); // number | undefined
54
- console.log(feature.properties); // fetched lazily from WASM
56
+ console.log(feature.properties); // read from the decoded columns
55
57
  console.log(feature.loadGeometry()); // Point[][]
56
58
  }
57
59
  }
58
60
  ```
59
61
 
62
+ ### Columns
63
+
64
+ `decodeTileColumns` hands each layer over as the typed arrays it decodes to, for consumers that
65
+ build their own buffers, such as a renderer. Nothing per feature crosses the WASM boundary.
66
+
67
+ ```ts
68
+ import { columnValue, decodeTileColumns } from '@maplibre/mlt-wasm';
69
+
70
+ for (const layer of decodeTileColumns(data).layers) {
71
+ const { dimension, vertices, zStep } = layer.geometry;
72
+ // vertices: Int32Array of (x, y) pairs, or (x, y, z) triples when dimension is 3
73
+ // geometryOffsets, partOffsets, ringOffsets: cumulative offsets, left out when not needed
74
+ // triangleOffsets, indexBuffer: present on tessellated layers
75
+ for (const column of layer.properties) {
76
+ // column.values has one slot per feature; a slot without a value holds 0 or ""
77
+ for (let f = 0; f < layer.featureCount; f++) {
78
+ const value = columnValue(column, f); // undefined when feature f has no value
79
+ }
80
+ }
81
+ // v2 vertex-scoped (m-value) and nested columns are not passed on
82
+ }
83
+ ```
84
+
85
+ `decodeTileColumns(data, { layers: ['roads', 'water'] })` decodes only the layers with those names,
86
+ every one that has it, since layer names need not be unique. The other layers are skipped undecoded.
87
+
88
+ Each column is `{ name, type, values, present? }`. `present` is a bitmap with one bit per
89
+ feature, LSB-first, left out when every feature has a value. `bool` comes as `0`/`1`, and
90
+ 64-bit integers, ids included, as `Float64Array`, so values above `Number.MAX_SAFE_INTEGER`
91
+ lose precision.
92
+
93
+ A 3D layer's `zStep` is the power of ten of its z grid's step in metres; `toElevation(z, zStep)`
94
+ converts one z to metres, exactly as `mlt-core` does.
95
+
96
+ ### Features
97
+
98
+ `featureGeometry(layer, i)` reads feature `i` of a column layer without knowing the offset levels.
99
+ Its points, lines and polygon rings are views of the layer's vertices, still in tile coordinates,
100
+ and a polygon's rings come ready for earcut. A `TessPolygonsWithOutlines` layer's triangles come per
101
+ feature, counted from the feature's own vertices. A `TessPolygons` layer stores triangles without
102
+ outlines, so `featureGeometry` rejects it; its `indexBuffer` and `triangleOffsets` are the triangles.
103
+
104
+ ```ts
105
+ import { featureGeometry } from '@maplibre/mlt-wasm';
106
+
107
+ const g = featureGeometry(layer, i);
108
+ if (g.kind === 'polygon') {
109
+ for (const { vertices, holeIndices } of g.polygons) {
110
+ const triangles = earcut(vertices, holeIndices, layer.geometry.dimension);
111
+ }
112
+ }
113
+ ```
114
+
115
+ #### Building GPU buffers
116
+
117
+ `layer.geometry.vertices` can be uploaded as the vertex buffer as it is: `dimension` integers per
118
+ vertex, read as `ivec2` or `ivec3` in the shader. What a renderer adds next to it depends on whether
119
+ its shapes need tessellation on the CPU.
120
+
121
+ Shapes drawn as they are, such as points and lines (thick lines can be extruded in the vertex
122
+ shader), need to know where each line starts, to break lines apart, and which feature it belongs to,
123
+ to style or pick it. `geometryStarts(layer.geometry)` gives both for the whole layer, from the tile's
124
+ own offset levels: where each feature's geometries start, where each geometry's vertices start and, in
125
+ a layer with polygons, where each polygon's rings and each ring's vertices start. The tile stores
126
+ these as counts per level, not per vertex, and the arrays are their running totals. Each has one
127
+ entry more than it has items, and stored offset columns come back as they are. They are resolved once
128
+ per layer and every call returns the same arrays, so don't modify them.
129
+
130
+ In a layer of one geometry kind they are what a renderer takes for a batch, such as deck.gl's binary
131
+ `PathLayer` for lines:
132
+
133
+ ```ts
134
+ import { geometryStarts } from '@maplibre/mlt-wasm';
135
+
136
+ const { featureGeometries, geometryVertices, ringVertices } = geometryStarts(layer.geometry);
137
+ // Lines: line g is vertices geometryVertices[g] .. geometryVertices[g + 1], and feature f's lines
138
+ // are featureGeometries[f] .. featureGeometries[f + 1].
139
+ new PathLayer({
140
+ data: {
141
+ length: geometryVertices.length - 1,
142
+ startIndices: geometryVertices,
143
+ attributes: { getPath: { value: layer.geometry.vertices, size: layer.geometry.dimension } },
144
+ },
145
+ _pathType: 'open',
146
+ });
147
+ // Polygons: geometryVertices starts each polygon, ringVertices each ring (outlines without the
148
+ // closing vertex).
149
+ ```
150
+
151
+ A shader that extrudes lines itself reads one vertex at a time, so it needs the line as a vertex
152
+ attribute instead. That is one fill per line from the same starts, done by the renderer for the id it
153
+ uploads:
154
+
155
+ ```ts
156
+ // A segment is drawn only if both ends are the same line.
157
+ const lineOfVertex = new Uint32Array(geometryVertices[geometryVertices.length - 1]);
158
+ for (let g = 0; g + 1 < geometryVertices.length; g++) {
159
+ lineOfVertex.fill(g, geometryVertices[g], geometryVertices[g + 1]);
160
+ }
161
+ ```
162
+
163
+ A geometry is a point, a line or a polygon, and every kind shares one sequence in feature order, so in
164
+ a layer mixing kinds, `layer.geometry.types` tells which features are which. A `TessPolygons` layer has
165
+ no runs of vertices, only triangles, so `geometryStarts` rejects it.
166
+
167
+ On a 1.3 MB tile of 1,333 line features and 524,482 vertices, `geometryStarts` takes about 0.006 ms
168
+ and the fill above about 0.2 ms, against about 3.8 ms for `decodeTileColumns` (Node, one machine).
169
+
170
+ Shapes that need tessellation on the CPU work one polygon or line at a time:
171
+
172
+ - A tessellation that only adds triangles keeps the vertex buffer: earcut's indices are counted from a
173
+ polygon's view in `featureGeometry`, which comes with its hole indices, so adding its `firstVertex`
174
+ makes them an index buffer over `vertices`. A tessellated layer's triangles are that already.
175
+ - A tessellation that creates vertices, such as ribbons with joins built on the CPU or extruded walls,
176
+ reads each line or ring between its starts, writes a buffer of its own, and tags its output with the
177
+ line or feature it came from.
178
+
60
179
  ### 3D
61
180
 
62
181
  `decodeTile3D` reads a tile whose every layer has z coordinates. Its features have the same
63
182
  `loadGeometry()` and `loadPolygons()`, with every vertex an `[x, y, z]` array, so the rest of the
64
183
  code can assume 3D. It throws when any layer has no z coordinates, for which `decodeTile` reads the
65
184
  tile in 2D, and when any layer uses the `TessPolygons` or `TessPolygonsWithOutlines` geometry
66
- layout, since tessellation is not supported in 3D.
185
+ layout. `decodeTileColumns` reads every layout, in 2D and 3D.
67
186
 
68
- Like `x` and `y`, `z` is the stored integer: it lies on the layer's `zStep` grid, and its
69
- elevation is `-10000 + z * 10 ** zStep` metres.
187
+ Like `x` and `y`, `z` is the stored integer: it lies on the layer's `zStep` grid, and
188
+ `toElevation(z, layer.zStep)` gives its elevation in metres.
70
189
 
71
190
  ```ts
72
191
  import { decodeTile3D } from '@maplibre/mlt-wasm';
@@ -0,0 +1,121 @@
1
+ /** Mirrors `GeometryType` in mlt-core - preserves the single vs multi distinction that MVT collapses. */
2
+ export declare enum MltGeometryType {
3
+ Point = 0,
4
+ LineString = 1,
5
+ Polygon = 2,
6
+ MultiPoint = 3,
7
+ MultiLineString = 4,
8
+ MultiPolygon = 5
9
+ }
10
+ /**
11
+ * The array each column type comes as, one value per feature.
12
+ *
13
+ * `bool` comes as `0`/`1` in a `Uint8Array`. `i64` and `u64` come as `Float64Array`, so values
14
+ * above `Number.MAX_SAFE_INTEGER` lose precision.
15
+ */
16
+ interface MltColumnValuesByType {
17
+ bool: Uint8Array;
18
+ i8: Int8Array;
19
+ u8: Uint8Array;
20
+ i32: Int32Array;
21
+ u32: Uint32Array;
22
+ i64: Float64Array;
23
+ u64: Float64Array;
24
+ f32: Float32Array;
25
+ f64: Float64Array;
26
+ string: string[];
27
+ }
28
+ /** The type a property column was stored as. */
29
+ export type MltColumnType = keyof MltColumnValuesByType;
30
+ export type MltColumnValues = MltColumnValuesByType[MltColumnType];
31
+ /**
32
+ * A slot whose feature has no value holds `0` or `""`; `present` says which slots those are.
33
+ * `present` is one bit per feature, LSB-first, and is left out when every feature has a value.
34
+ */
35
+ export interface MltColumn<V extends MltColumnValues = MltColumnValues> {
36
+ readonly values: V;
37
+ readonly present?: Uint8Array;
38
+ }
39
+ /** A property column. Checking `type` narrows `values` to its array. */
40
+ export type MltNamedColumn = {
41
+ [T in MltColumnType]: MltColumn<MltColumnValuesByType[T]> & {
42
+ readonly name: string;
43
+ readonly type: T;
44
+ };
45
+ }[MltColumnType];
46
+ /**
47
+ * A layer's geometry as decoded, 2D or 3D by `dimension`.
48
+ *
49
+ * Offset arrays are cumulative: entry `i` starts item `i` and entry `i + 1` ends it.
50
+ * Each level indexes into the next, and the last one present indexes vertices.
51
+ * An array a layer does not need is left out.
52
+ */
53
+ export type MltGeometryColumns = MltGeometryColumns2D | MltGeometryColumns3D;
54
+ interface MltGeometryColumnsBase {
55
+ /** The MLT geometry type of each feature, see `MltGeometryType`. */
56
+ readonly types: Uint8Array;
57
+ readonly geometryOffsets?: Uint32Array;
58
+ readonly partOffsets?: Uint32Array;
59
+ readonly ringOffsets?: Uint32Array;
60
+ /**
61
+ * `dimension` words per vertex, in tile coordinates, interleaved as the wire stores them.
62
+ * A polygon ring's closing vertex is not stored.
63
+ */
64
+ readonly vertices: Int32Array;
65
+ /** Cumulative triangle counts per polygon feature, for a tessellated layer. */
66
+ readonly triangleOffsets?: Uint32Array;
67
+ /** Three vertex indices per triangle, counted from the layer's first vertex. */
68
+ readonly indexBuffer?: Uint32Array;
69
+ }
70
+ /** `(x, y)` vertices. */
71
+ export interface MltGeometryColumns2D extends MltGeometryColumnsBase {
72
+ readonly dimension: 2;
73
+ readonly zStep?: undefined;
74
+ }
75
+ /** `(x, y, z)` vertices. */
76
+ export interface MltGeometryColumns3D extends MltGeometryColumnsBase {
77
+ readonly dimension: 3;
78
+ /** The z grid as the power of ten of its step in metres; `toElevation` gives a z in metres. */
79
+ readonly zStep: number;
80
+ }
81
+ export interface MltColumnLayer {
82
+ readonly name: string;
83
+ readonly extent: number;
84
+ /** The wire version the layer was stored in. */
85
+ readonly version: 1 | 2;
86
+ readonly featureCount: number;
87
+ readonly geometry: MltGeometryColumns;
88
+ /** Left out when the layer has no id column. */
89
+ readonly ids?: MltColumn<Float64Array>;
90
+ /**
91
+ * In wire order, a shared dictionary's children named by its prefix and their own names.
92
+ * v2 vertex-scoped (m-value) and nested columns are not passed on.
93
+ */
94
+ readonly properties: readonly MltNamedColumn[];
95
+ }
96
+ export interface MltColumnTile {
97
+ /** In wire order; layer names need not be unique. */
98
+ readonly layers: readonly MltColumnLayer[];
99
+ }
100
+ export interface DecodeTileColumnsOptions {
101
+ /**
102
+ * Decode only the layers with one of these names, every one that has it. The other
103
+ * layers are skipped without being decoded. Every layer is decoded when left out.
104
+ */
105
+ readonly layers?: readonly string[];
106
+ }
107
+ /** Decode the layers of a tile into typed arrays. */
108
+ export declare function decodeTileColumns(data: Uint8Array, options?: DecodeTileColumnsOptions): MltColumnTile;
109
+ /**
110
+ * Feature `index`'s value in `column`, or `undefined` when the feature has none.
111
+ *
112
+ * Throws when `index` is not a feature, so that `undefined` only ever means no value.
113
+ */
114
+ export declare function columnValue<C extends MltColumn>(column: C, index: number): C["values"][number] | undefined;
115
+ /**
116
+ * A z of a 3D layer in metres, `-10000 + z * 10 ** zStep`, as mlt-core's `ZStep::elevation`:
117
+ * a fine grid divides last, so `1001234` on the `-2` grid is exactly `12.34`.
118
+ */
119
+ export declare function toElevation(z: number, zStep: number): number;
120
+ export {};
121
+ //# sourceMappingURL=columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.d.ts","sourceRoot":"","sources":["../js/columns.ts"],"names":[],"mappings":"AAEA,yGAAyG;AACzG,oBAAY,eAAe;IACzB,KAAK,IAAI;IACT,UAAU,IAAI;IACd,OAAO,IAAI;IACX,UAAU,IAAI;IACd,eAAe,IAAI;IACnB,YAAY,IAAI;CACjB;AAED;;;;;GAKG;AACH,UAAU,qBAAqB;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,SAAS,CAAC;IACd,EAAE,EAAE,UAAU,CAAC;IACf,GAAG,EAAE,UAAU,CAAC;IAChB,GAAG,EAAE,WAAW,CAAC;IACjB,GAAG,EAAE,YAAY,CAAC;IAClB,GAAG,EAAE,YAAY,CAAC;IAClB,GAAG,EAAE,YAAY,CAAC;IAClB,GAAG,EAAE,YAAY,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG,MAAM,qBAAqB,CAAC;AAExD,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe;IACpE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnB,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;CAC/B;AAED,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG;KAC1B,CAAC,IAAI,aAAa,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAAG;QAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,EAAE,CAAC,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IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,cAAc,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED,qDAAqD;AACrD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,wBAA6B,GACrC,aAAa,CAIf;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAC7C,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,MAAM,GACZ,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,CAQjC;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG5D"}
@@ -0,0 +1,39 @@
1
+ import { wasmDecodeTileColumns } from "./wasm";
2
+ /** Mirrors `GeometryType` in mlt-core - preserves the single vs multi distinction that MVT collapses. */
3
+ export var MltGeometryType;
4
+ (function (MltGeometryType) {
5
+ MltGeometryType[MltGeometryType["Point"] = 0] = "Point";
6
+ MltGeometryType[MltGeometryType["LineString"] = 1] = "LineString";
7
+ MltGeometryType[MltGeometryType["Polygon"] = 2] = "Polygon";
8
+ MltGeometryType[MltGeometryType["MultiPoint"] = 3] = "MultiPoint";
9
+ MltGeometryType[MltGeometryType["MultiLineString"] = 4] = "MultiLineString";
10
+ MltGeometryType[MltGeometryType["MultiPolygon"] = 5] = "MultiPolygon";
11
+ })(MltGeometryType || (MltGeometryType = {}));
12
+ /** Decode the layers of a tile into typed arrays. */
13
+ export function decodeTileColumns(data, options = {}) {
14
+ // wasm-bindgen copies the array into Rust, so it never sees the caller's readonly one.
15
+ const names = options.layers;
16
+ return { layers: wasmDecodeTileColumns(data, names) };
17
+ }
18
+ /**
19
+ * Feature `index`'s value in `column`, or `undefined` when the feature has none.
20
+ *
21
+ * Throws when `index` is not a feature, so that `undefined` only ever means no value.
22
+ */
23
+ export function columnValue(column, index) {
24
+ const { values, present } = column;
25
+ if (!Number.isInteger(index) || index < 0 || index >= values.length) {
26
+ throw new RangeError(`the column has no feature ${index}`);
27
+ }
28
+ const has = present === undefined || ((present[index >> 3] >> (index & 7)) & 1) === 1;
29
+ return has ? values[index] : undefined;
30
+ }
31
+ /**
32
+ * A z of a 3D layer in metres, `-10000 + z * 10 ** zStep`, as mlt-core's `ZStep::elevation`:
33
+ * a fine grid divides last, so `1001234` on the `-2` grid is exactly `12.34`.
34
+ */
35
+ export function toElevation(z, zStep) {
36
+ const power = 10 ** Math.abs(zStep);
37
+ return zStep < 0 ? (z - 10000 * power) / power : -10000 + z * power;
38
+ }
39
+ //# sourceMappingURL=columns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.js","sourceRoot":"","sources":["../js/columns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAE/C,yGAAyG;AACzG,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,uDAAS,CAAA;IACT,iEAAc,CAAA;IACd,2DAAW,CAAA;IACX,iEAAc,CAAA;IACd,2EAAmB,CAAA;IACnB,qEAAgB,CAAA;AAClB,CAAC,EAPW,eAAe,KAAf,eAAe,QAO1B;AA+GD,qDAAqD;AACrD,MAAM,UAAU,iBAAiB,CAC/B,IAAgB,EAChB,UAAoC,EAAE;IAEtC,uFAAuF;IACvF,MAAM,KAAK,GAAG,OAAO,CAAC,MAA8B,CAAC;IACrD,OAAO,EAAE,MAAM,EAAE,qBAAqB,CAAC,IAAI,EAAE,KAAK,CAAqB,EAAE,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,MAAS,EACT,KAAa;IAEb,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACpE,MAAM,IAAI,UAAU,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,GAAG,GACP,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC5E,OAAO,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,KAAa;IAClD,MAAM,KAAK,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC;AACtE,CAAC"}
@@ -0,0 +1,107 @@
1
+ import { type MltColumnLayer, type MltGeometryColumns, MltGeometryType } from "./columns";
2
+ /**
3
+ * One feature's geometry as views into its layer's buffers: nothing is copied but a
4
+ * tessellated feature's triangles. Coordinates stay as decoded, in tile coordinates with z
5
+ * (when `dimension` is 3) on the layer's grid.
6
+ */
7
+ export type MltFeatureGeometry = MltPointGeometry | MltLineGeometry | MltPolygonGeometry;
8
+ interface MltFeatureGeometryBase {
9
+ readonly type: MltGeometryType;
10
+ /** This feature's vertices, `dimension` words each. */
11
+ readonly vertices: Int32Array;
12
+ /**
13
+ * Where `vertices` starts in the layer's vertex sequence, which per-vertex arrays run over.
14
+ */
15
+ readonly firstVertex: number;
16
+ }
17
+ /** A `Point` or `MultiPoint`: each vertex is a point. */
18
+ export interface MltPointGeometry extends MltFeatureGeometryBase {
19
+ readonly kind: "point";
20
+ }
21
+ /** A `LineString` or `MultiLineString`. */
22
+ export interface MltLineGeometry extends MltFeatureGeometryBase {
23
+ readonly kind: "line";
24
+ readonly lines: readonly MltVertexRun[];
25
+ }
26
+ /** A `Polygon` or `MultiPolygon`. */
27
+ export interface MltPolygonGeometry extends MltFeatureGeometryBase {
28
+ readonly kind: "polygon";
29
+ /** Each polygon's rings, ready for `earcut(vertices, holeIndices, dimension)`. */
30
+ readonly polygons: readonly MltPolygonRings[];
31
+ /**
32
+ * Three indices into `vertices` per triangle, for a `TessPolygonsWithOutlines` layer: the
33
+ * triangles of every polygon of the feature. Left `undefined` when the layer is not tessellated.
34
+ */
35
+ readonly triangles: Uint32Array | undefined;
36
+ }
37
+ /** One line, or one ring, as a view of its vertices. */
38
+ export interface MltVertexRun {
39
+ readonly vertices: Int32Array;
40
+ /** Where `vertices` starts in the layer's vertex sequence. */
41
+ readonly firstVertex: number;
42
+ }
43
+ export interface MltPolygonRings extends MltVertexRun {
44
+ /** Where each hole starts in `vertices`, counted in vertices; the shell comes first. */
45
+ readonly holeIndices: number[];
46
+ }
47
+ /** A `TessPolygons` layer: triangles, and no outlines to walk. */
48
+ export declare function isTrianglesOnly(geometry: MltGeometryColumns): boolean;
49
+ /** The first geometry (point, line or polygon) of feature `index`; `index + 1` gives its end. */
50
+ export declare function geometryStart(geometry: MltGeometryColumns, index: number): number;
51
+ /**
52
+ * The first vertex of line `line`, which is one part, and in a layer with rings, one ring.
53
+ * Over a feature's geometry run, from `geometryStart`, it bounds the feature's vertices too.
54
+ */
55
+ export declare function lineStart(geometry: MltGeometryColumns, line: number): number;
56
+ /** The levels a polygon's rings are read from: a layer storing polygons has both. */
57
+ export declare function polygonLevels(geometry: MltGeometryColumns): [parts: Uint32Array, rings: Uint32Array];
58
+ /** The vertices in `start..end`. Throws when an offset level runs backwards. */
59
+ export declare function runLength(start: number, end: number): number;
60
+ /**
61
+ * Where each feature's geometries, each geometry's vertices and, in a layer with polygons, each
62
+ * polygon's rings start: the layer's offset levels resolved down to its vertex sequence, for
63
+ * building buffers for every feature at once.
64
+ *
65
+ * Each array has one entry more than it has items: item `i` runs from `array[i]` to
66
+ * `array[i + 1]`. A geometry is a point, a line or a polygon; a feature has one, or several when
67
+ * it is a multi-geometry. Every geometry kind shares one sequence, in feature order, so in a
68
+ * layer of one kind the starts are what a renderer takes for a batch of paths or polygons.
69
+ */
70
+ export interface MltGeometryStarts {
71
+ /** Feature `f` has geometries `featureGeometries[f] .. featureGeometries[f + 1]`. */
72
+ readonly featureGeometries: Uint32Array;
73
+ /**
74
+ * Geometry `g` has vertices `geometryVertices[g] .. geometryVertices[g + 1]`: a point's one,
75
+ * a line's, or a polygon's, its rings one after another.
76
+ */
77
+ readonly geometryVertices: Uint32Array;
78
+ /**
79
+ * In a layer storing polygons, geometry `g` has rings `geometryRings[g] .. geometryRings[g + 1]`:
80
+ * a polygon's shell, then its holes. A point or line of such a layer is one ring of its own.
81
+ * Left out when the layer has no rings.
82
+ */
83
+ readonly geometryRings?: Uint32Array;
84
+ /**
85
+ * Ring `r` has vertices `ringVertices[r] .. ringVertices[r + 1]`, without the closing vertex,
86
+ * which is not stored. Left out when the layer has no rings.
87
+ */
88
+ readonly ringVertices?: Uint32Array;
89
+ }
90
+ /**
91
+ * The starts of `geometry`'s features, geometries and rings, as `MltGeometryStarts`. Stored
92
+ * offset columns are returned as they are; levels the layer leaves out are filled in. They are
93
+ * resolved once per layer, and every call returns the same arrays, so they must not be modified.
94
+ *
95
+ * Throws for a `TessPolygons` layer, which stores triangles and no runs of vertices (see
96
+ * `indexBuffer` and `triangleOffsets`), and when the offset levels are inconsistent.
97
+ */
98
+ export declare function geometryStarts(geometry: MltGeometryColumns): MltGeometryStarts;
99
+ /**
100
+ * Feature `index` of `layer`, as views into the layer's buffers.
101
+ *
102
+ * Throws when `index` is not a feature of the layer, and for a `TessPolygons` layer, which
103
+ * stores triangles and no outlines: read its `indexBuffer` and `triangleOffsets` instead.
104
+ */
105
+ export declare function featureGeometry(layer: MltColumnLayer, index: number): MltFeatureGeometry;
106
+ export {};
107
+ //# sourceMappingURL=featureGeometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"featureGeometry.d.ts","sourceRoot":"","sources":["../js/featureGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,eAAe,EAChB,MAAM,WAAW,CAAC;AAEnB;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAC1B,gBAAgB,GAChB,eAAe,GACf,kBAAkB,CAAC;AAEvB,UAAU,sBAAsB;IAC9B,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,yDAAyD;AACzD,MAAM,WAAW,gBAAiB,SAAQ,sBAAsB;IAC9D,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,2CAA2C;AAC3C,MAAM,WAAW,eAAgB,SAAQ,sBAAsB;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;CACzC;AAED,qCAAqC;AACrC,MAAM,WAAW,kBAAmB,SAAQ,sBAAsB;IAChE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,CAAC;IAC9C;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;CAC7C;AAED,wDAAwD;AAC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