@maplibre/mlt 1.1.1 → 1.1.2
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/dist/decoding/decodingUtils.js +2 -2
- package/dist/decoding/decodingUtils.js.map +1 -1
- package/dist/decoding/geometryDecoder.js +8 -8
- package/dist/decoding/geometryDecoder.js.map +1 -1
- package/dist/decoding/integerDecodingUtils.d.ts +1 -1
- package/dist/decoding/integerDecodingUtils.js.map +1 -1
- package/dist/decoding/integerStreamDecoder.d.ts +1 -1
- package/dist/decoding/integerStreamDecoder.js.map +1 -1
- package/dist/decoding/integerStreamDecoder.spec.js +22 -4
- package/dist/decoding/integerStreamDecoder.spec.js.map +1 -1
- package/dist/decoding/propertyDecoder.js +10 -10
- package/dist/decoding/propertyDecoder.js.map +1 -1
- package/dist/decoding/propertyDecoder.spec.js +27 -24
- package/dist/decoding/propertyDecoder.spec.js.map +1 -1
- package/dist/decoding/stringDecoder.d.ts +2 -10
- package/dist/decoding/stringDecoder.js +149 -157
- package/dist/decoding/stringDecoder.js.map +1 -1
- package/dist/decoding/stringDecoder.spec.js +10 -10
- package/dist/decoding/stringDecoder.spec.js.map +1 -1
- package/dist/metadata/tile/streamMetadataDecoder.d.ts +28 -4
- package/dist/metadata/tile/streamMetadataDecoder.js +81 -15
- package/dist/metadata/tile/streamMetadataDecoder.js.map +1 -1
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.js +4 -4
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.js.map +1 -1
- package/dist/metadata/tileset/typeMap.d.ts +21 -29
- package/dist/metadata/tileset/typeMap.js +167 -169
- package/dist/metadata/tileset/typeMap.js.map +1 -1
- package/dist/mltDecoder.js +11 -9
- package/dist/mltDecoder.js.map +1 -1
- package/dist/vector/geometry/geometryVector.js +2 -2
- package/dist/vector/geometry/geometryVector.js.map +1 -1
- package/dist/vector/geometry/geometryVectorConverter.js +4 -4
- package/dist/vector/geometry/geometryVectorConverter.js.map +1 -1
- package/dist/vector/geometry/zOrderCurve.d.ts +4 -17
- package/dist/vector/geometry/zOrderCurve.js +10 -35
- package/dist/vector/geometry/zOrderCurve.js.map +1 -1
- package/dist/vector/geometry/zOrderCurve.spec.js +15 -10
- package/dist/vector/geometry/zOrderCurve.spec.js.map +1 -1
- package/package.json +1 -1
- package/dist/metadata/tile/mortonEncodedStreamMetadata.d.ts +0 -15
- package/dist/metadata/tile/mortonEncodedStreamMetadata.js +0 -27
- package/dist/metadata/tile/mortonEncodedStreamMetadata.js.map +0 -1
- package/dist/metadata/tile/rleEncodedStreamMetadata.d.ts +0 -24
- package/dist/metadata/tile/rleEncodedStreamMetadata.js +0 -38
- package/dist/metadata/tile/rleEncodedStreamMetadata.js.map +0 -1
- package/dist/metadata/tile/streamMetadata.d.ts +0 -29
- package/dist/metadata/tile/streamMetadata.js +0 -82
- package/dist/metadata/tile/streamMetadata.js.map +0 -1
- package/dist/vector/geometry/spaceFillingCurve.d.ts +0 -22
- package/dist/vector/geometry/spaceFillingCurve.js +0 -31
- package/dist/vector/geometry/spaceFillingCurve.js.map +0 -1
|
@@ -7,183 +7,181 @@ import { ColumnScope, ComplexType, ScalarType, } from "./tilesetMetadata";
|
|
|
7
7
|
* - Whether the column has children (typeCode == 30 for STRUCT)
|
|
8
8
|
* - For ID types: whether it uses long (64-bit) IDs
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return column;
|
|
33
|
-
}
|
|
34
|
-
case 4: {
|
|
35
|
-
// GEOMETRY (non-nullable, no children)
|
|
36
|
-
const column = {};
|
|
37
|
-
column.nullable = false;
|
|
38
|
-
column.columnScope = ColumnScope.FEATURE;
|
|
39
|
-
const complexCol = {};
|
|
40
|
-
complexCol.type = "physicalType";
|
|
41
|
-
complexCol.physicalType = ComplexType.GEOMETRY;
|
|
42
|
-
column.type = "complexType";
|
|
43
|
-
column.complexType = complexCol;
|
|
44
|
-
return column;
|
|
45
|
-
}
|
|
46
|
-
case 30: {
|
|
47
|
-
// STRUCT (non-nullable with children)
|
|
48
|
-
const column = {};
|
|
49
|
-
column.nullable = false;
|
|
50
|
-
column.columnScope = ColumnScope.FEATURE;
|
|
51
|
-
const complexCol = {};
|
|
52
|
-
complexCol.type = "physicalType";
|
|
53
|
-
complexCol.physicalType = ComplexType.STRUCT;
|
|
54
|
-
column.type = "complexType";
|
|
55
|
-
column.complexType = complexCol;
|
|
56
|
-
return column;
|
|
57
|
-
}
|
|
58
|
-
default:
|
|
59
|
-
return this.mapScalarType(typeCode);
|
|
10
|
+
/**
|
|
11
|
+
* Decodes a type code into a Column structure.
|
|
12
|
+
* ID columns (0-3) are represented as physical UINT_32 or UINT_64 types in TypeScript
|
|
13
|
+
*/
|
|
14
|
+
export function decodeColumnType(typeCode) {
|
|
15
|
+
switch (typeCode) {
|
|
16
|
+
case 0:
|
|
17
|
+
case 1:
|
|
18
|
+
case 2:
|
|
19
|
+
case 3: {
|
|
20
|
+
// ID columns: 0=uint32, 1=uint64, 2=nullable uint32, 3=nullable uint64
|
|
21
|
+
const column = {};
|
|
22
|
+
column.nullable = (typeCode & 1) !== 0; // Bit 0 = nullable;
|
|
23
|
+
column.columnScope = ColumnScope.FEATURE;
|
|
24
|
+
const scalarCol = {};
|
|
25
|
+
// Map to physical type since TS schema doesn't have LogicalScalarType.ID
|
|
26
|
+
const physicalType = typeCode > 1 ? ScalarType.UINT_64 : ScalarType.UINT_32; // Bit 1 = longID
|
|
27
|
+
scalarCol.physicalType = physicalType;
|
|
28
|
+
scalarCol.type = "physicalType";
|
|
29
|
+
column.scalarType = scalarCol;
|
|
30
|
+
column.type = "scalarType";
|
|
31
|
+
return column;
|
|
60
32
|
}
|
|
33
|
+
case 4: {
|
|
34
|
+
// GEOMETRY (non-nullable, no children)
|
|
35
|
+
const column = {};
|
|
36
|
+
column.nullable = false;
|
|
37
|
+
column.columnScope = ColumnScope.FEATURE;
|
|
38
|
+
const complexCol = {};
|
|
39
|
+
complexCol.type = "physicalType";
|
|
40
|
+
complexCol.physicalType = ComplexType.GEOMETRY;
|
|
41
|
+
column.type = "complexType";
|
|
42
|
+
column.complexType = complexCol;
|
|
43
|
+
return column;
|
|
44
|
+
}
|
|
45
|
+
case 30: {
|
|
46
|
+
// STRUCT (non-nullable with children)
|
|
47
|
+
const column = {};
|
|
48
|
+
column.nullable = false;
|
|
49
|
+
column.columnScope = ColumnScope.FEATURE;
|
|
50
|
+
const complexCol = {};
|
|
51
|
+
complexCol.type = "physicalType";
|
|
52
|
+
complexCol.physicalType = ComplexType.STRUCT;
|
|
53
|
+
column.type = "complexType";
|
|
54
|
+
column.complexType = complexCol;
|
|
55
|
+
return column;
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
return mapScalarType(typeCode);
|
|
61
59
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns true if this type code requires a name to be stored.
|
|
63
|
+
* ID (0-3) and GEOMETRY (4) columns have implicit names.
|
|
64
|
+
* All other types (>= 10) require explicit names.
|
|
65
|
+
*/
|
|
66
|
+
export function columnTypeHasName(typeCode) {
|
|
67
|
+
return typeCode >= 10;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns true if this type code has child fields.
|
|
71
|
+
* Only STRUCT (typeCode 30) has children.
|
|
72
|
+
*/
|
|
73
|
+
export function columnTypeHasChildren(typeCode) {
|
|
74
|
+
return typeCode === 30;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Determines if a stream count needs to be read for this column.
|
|
78
|
+
* Mirrors the logic in cpp/include/mlt/metadata/type_map.hpp lines 81-118
|
|
79
|
+
*/
|
|
80
|
+
export function hasStreamCount(column) {
|
|
81
|
+
// ID columns don't have stream count (identified by name)
|
|
82
|
+
if (column.name === "id") {
|
|
83
|
+
return false;
|
|
76
84
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
case ScalarType.INT_64:
|
|
97
|
-
case ScalarType.UINT_64:
|
|
98
|
-
case ScalarType.FLOAT:
|
|
99
|
-
case ScalarType.DOUBLE:
|
|
100
|
-
return false;
|
|
101
|
-
case ScalarType.STRING:
|
|
102
|
-
return true;
|
|
103
|
-
default:
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (scalarCol.type === "logicalType") {
|
|
108
|
-
return false;
|
|
85
|
+
if (column.type === "scalarType") {
|
|
86
|
+
const scalarCol = column.scalarType;
|
|
87
|
+
if (scalarCol.type === "physicalType") {
|
|
88
|
+
const physicalType = scalarCol.physicalType;
|
|
89
|
+
switch (physicalType) {
|
|
90
|
+
case ScalarType.BOOLEAN:
|
|
91
|
+
case ScalarType.INT_8:
|
|
92
|
+
case ScalarType.UINT_8:
|
|
93
|
+
case ScalarType.INT_32:
|
|
94
|
+
case ScalarType.UINT_32:
|
|
95
|
+
case ScalarType.INT_64:
|
|
96
|
+
case ScalarType.UINT_64:
|
|
97
|
+
case ScalarType.FLOAT:
|
|
98
|
+
case ScalarType.DOUBLE:
|
|
99
|
+
return false;
|
|
100
|
+
case ScalarType.STRING:
|
|
101
|
+
return true;
|
|
102
|
+
default:
|
|
103
|
+
return false;
|
|
109
104
|
}
|
|
110
105
|
}
|
|
111
|
-
else if (
|
|
112
|
-
|
|
113
|
-
if (complexCol.type === "physicalType") {
|
|
114
|
-
const physicalType = complexCol.physicalType;
|
|
115
|
-
switch (physicalType) {
|
|
116
|
-
case ComplexType.GEOMETRY:
|
|
117
|
-
case ComplexType.STRUCT:
|
|
118
|
-
return true;
|
|
119
|
-
default:
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
106
|
+
else if (scalarCol.type === "logicalType") {
|
|
107
|
+
return false;
|
|
123
108
|
}
|
|
124
|
-
console.warn("Unexpected column type in hasStreamCount", column);
|
|
125
|
-
return false;
|
|
126
109
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
break;
|
|
139
|
-
case 12:
|
|
140
|
-
case 13:
|
|
141
|
-
scalarType = ScalarType.INT_8;
|
|
142
|
-
break;
|
|
143
|
-
case 14:
|
|
144
|
-
case 15:
|
|
145
|
-
scalarType = ScalarType.UINT_8;
|
|
146
|
-
break;
|
|
147
|
-
case 16:
|
|
148
|
-
case 17:
|
|
149
|
-
scalarType = ScalarType.INT_32;
|
|
150
|
-
break;
|
|
151
|
-
case 18:
|
|
152
|
-
case 19:
|
|
153
|
-
scalarType = ScalarType.UINT_32;
|
|
154
|
-
break;
|
|
155
|
-
case 20:
|
|
156
|
-
case 21:
|
|
157
|
-
scalarType = ScalarType.INT_64;
|
|
158
|
-
break;
|
|
159
|
-
case 22:
|
|
160
|
-
case 23:
|
|
161
|
-
scalarType = ScalarType.UINT_64;
|
|
162
|
-
break;
|
|
163
|
-
case 24:
|
|
164
|
-
case 25:
|
|
165
|
-
scalarType = ScalarType.FLOAT;
|
|
166
|
-
break;
|
|
167
|
-
case 26:
|
|
168
|
-
case 27:
|
|
169
|
-
scalarType = ScalarType.DOUBLE;
|
|
170
|
-
break;
|
|
171
|
-
case 28:
|
|
172
|
-
case 29:
|
|
173
|
-
scalarType = ScalarType.STRING;
|
|
174
|
-
break;
|
|
175
|
-
default:
|
|
176
|
-
return null;
|
|
110
|
+
else if (column.type === "complexType") {
|
|
111
|
+
const complexCol = column.complexType;
|
|
112
|
+
if (complexCol.type === "physicalType") {
|
|
113
|
+
const physicalType = complexCol.physicalType;
|
|
114
|
+
switch (physicalType) {
|
|
115
|
+
case ComplexType.GEOMETRY:
|
|
116
|
+
case ComplexType.STRUCT:
|
|
117
|
+
return true;
|
|
118
|
+
default:
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
177
121
|
}
|
|
178
|
-
const column = {};
|
|
179
|
-
column.nullable = (typeCode & 1) !== 0;
|
|
180
|
-
column.columnScope = ColumnScope.FEATURE;
|
|
181
|
-
const scalarCol = {};
|
|
182
|
-
scalarCol.type = "physicalType";
|
|
183
|
-
scalarCol.physicalType = scalarType;
|
|
184
|
-
column.type = "scalarType";
|
|
185
|
-
column.scalarType = scalarCol;
|
|
186
|
-
return column;
|
|
187
122
|
}
|
|
123
|
+
console.warn("Unexpected column type in hasStreamCount", column);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Maps a scalar type code to a Column with ScalarType.
|
|
128
|
+
* Type codes 10-29 encode scalar types with nullable flag.
|
|
129
|
+
* Even codes are non-nullable, odd codes are nullable.
|
|
130
|
+
*/
|
|
131
|
+
function mapScalarType(typeCode) {
|
|
132
|
+
let scalarType = null;
|
|
133
|
+
switch (typeCode) {
|
|
134
|
+
case 10:
|
|
135
|
+
case 11:
|
|
136
|
+
scalarType = ScalarType.BOOLEAN;
|
|
137
|
+
break;
|
|
138
|
+
case 12:
|
|
139
|
+
case 13:
|
|
140
|
+
scalarType = ScalarType.INT_8;
|
|
141
|
+
break;
|
|
142
|
+
case 14:
|
|
143
|
+
case 15:
|
|
144
|
+
scalarType = ScalarType.UINT_8;
|
|
145
|
+
break;
|
|
146
|
+
case 16:
|
|
147
|
+
case 17:
|
|
148
|
+
scalarType = ScalarType.INT_32;
|
|
149
|
+
break;
|
|
150
|
+
case 18:
|
|
151
|
+
case 19:
|
|
152
|
+
scalarType = ScalarType.UINT_32;
|
|
153
|
+
break;
|
|
154
|
+
case 20:
|
|
155
|
+
case 21:
|
|
156
|
+
scalarType = ScalarType.INT_64;
|
|
157
|
+
break;
|
|
158
|
+
case 22:
|
|
159
|
+
case 23:
|
|
160
|
+
scalarType = ScalarType.UINT_64;
|
|
161
|
+
break;
|
|
162
|
+
case 24:
|
|
163
|
+
case 25:
|
|
164
|
+
scalarType = ScalarType.FLOAT;
|
|
165
|
+
break;
|
|
166
|
+
case 26:
|
|
167
|
+
case 27:
|
|
168
|
+
scalarType = ScalarType.DOUBLE;
|
|
169
|
+
break;
|
|
170
|
+
case 28:
|
|
171
|
+
case 29:
|
|
172
|
+
scalarType = ScalarType.STRING;
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const column = {};
|
|
178
|
+
column.nullable = (typeCode & 1) !== 0;
|
|
179
|
+
column.columnScope = ColumnScope.FEATURE;
|
|
180
|
+
const scalarCol = {};
|
|
181
|
+
scalarCol.type = "physicalType";
|
|
182
|
+
scalarCol.physicalType = scalarType;
|
|
183
|
+
column.type = "scalarType";
|
|
184
|
+
column.scalarType = scalarCol;
|
|
185
|
+
return column;
|
|
188
186
|
}
|
|
189
187
|
//# sourceMappingURL=typeMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeMap.js","sourceRoot":"","sources":["../../../src/metadata/tileset/typeMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,WAAW,EAEX,WAAW,EAEX,UAAU,GACb,MAAM,mBAAmB,C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AAM,CAAC,IAAI,GAAG,YAAY,CAAC;QAC3B,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;QAC9B,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ","sourcesContent":["import {\n type Column,\n ColumnScope,\n type ComplexColumn,\n ComplexType,\n type ScalarColumn,\n ScalarType,\n} from \"./tilesetMetadata\";\n\n/**\n * The type code is a single varint32 that encodes:\n * - Physical or logical type\n * - Nullable flag\n * - Whether the column has a name (typeCode >= 10)\n * - Whether the column has children (typeCode == 30 for STRUCT)\n * - For ID types: whether it uses long (64-bit) IDs\n */\nexport class TypeMap {\n /**\n * Decodes a type code into a Column structure.\n * ID columns (0-3) are represented as physical UINT_32 or UINT_64 types in TypeScript\n */\n static decodeColumnType(typeCode: number): Column | null {\n switch (typeCode) {\n case 0:\n case 1:\n case 2:\n case 3: {\n // ID columns: 0=uint32, 1=uint64, 2=nullable uint32, 3=nullable uint64\n const column = {} as Column;\n column.nullable = (typeCode & 1) !== 0; // Bit 0 = nullable;\n column.columnScope = ColumnScope.FEATURE;\n const scalarCol = {} as ScalarColumn;\n // Map to physical type since TS schema doesn't have LogicalScalarType.ID\n const physicalType = typeCode > 1 ? ScalarType.UINT_64 : ScalarType.UINT_32; // Bit 1 = longID\n scalarCol.physicalType = physicalType;\n scalarCol.type = \"physicalType\";\n column.scalarType = scalarCol;\n column.type = \"scalarType\";\n return column;\n }\n case 4: {\n // GEOMETRY (non-nullable, no children)\n const column = {} as Column;\n column.nullable = false;\n column.columnScope = ColumnScope.FEATURE;\n const complexCol = {} as ComplexColumn;\n complexCol.type = \"physicalType\";\n complexCol.physicalType = ComplexType.GEOMETRY;\n column.type = \"complexType\";\n column.complexType = complexCol;\n return column;\n }\n case 30: {\n // STRUCT (non-nullable with children)\n const column = {} as Column;\n column.nullable = false;\n column.columnScope = ColumnScope.FEATURE;\n const complexCol = {} as ComplexColumn;\n complexCol.type = \"physicalType\";\n complexCol.physicalType = ComplexType.STRUCT;\n column.type = \"complexType\";\n column.complexType = complexCol;\n return column;\n }\n default:\n return this.mapScalarType(typeCode);\n }\n }\n\n /**\n * Returns true if this type code requires a name to be stored.\n * ID (0-3) and GEOMETRY (4) columns have implicit names.\n * All other types (>= 10) require explicit names.\n */\n static columnTypeHasName(typeCode: number): boolean {\n return typeCode >= 10;\n }\n\n /**\n * Returns true if this type code has child fields.\n * Only STRUCT (typeCode 30) has children.\n */\n static columnTypeHasChildren(typeCode: number): boolean {\n return typeCode === 30;\n }\n\n /**\n * Determines if a stream count needs to be read for this column.\n * Mirrors the logic in cpp/include/mlt/metadata/type_map.hpp lines 81-118\n */\n static hasStreamCount(column: Column): boolean {\n // ID columns don't have stream count (identified by name)\n if (column.name === \"id\") {\n return false;\n }\n\n if (column.type === \"scalarType\") {\n const scalarCol = column.scalarType;\n\n if (scalarCol.type === \"physicalType\") {\n const physicalType = scalarCol.physicalType;\n switch (physicalType) {\n case ScalarType.BOOLEAN:\n case ScalarType.INT_8:\n case ScalarType.UINT_8:\n case ScalarType.INT_32:\n case ScalarType.UINT_32:\n case ScalarType.INT_64:\n case ScalarType.UINT_64:\n case ScalarType.FLOAT:\n case ScalarType.DOUBLE:\n return false;\n case ScalarType.STRING:\n return true;\n default:\n return false;\n }\n } else if (scalarCol.type === \"logicalType\") {\n return false;\n }\n } else if (column.type === \"complexType\") {\n const complexCol = column.complexType;\n\n if (complexCol.type === \"physicalType\") {\n const physicalType = complexCol.physicalType;\n switch (physicalType) {\n case ComplexType.GEOMETRY:\n case ComplexType.STRUCT:\n return true;\n default:\n return false;\n }\n }\n }\n\n console.warn(\"Unexpected column type in hasStreamCount\", column);\n return false;\n }\n\n /**\n * Maps a scalar type code to a Column with ScalarType.\n * Type codes 10-29 encode scalar types with nullable flag.\n * Even codes are non-nullable, odd codes are nullable.\n */\n private static mapScalarType(typeCode: number): Column | null {\n let scalarType: number | null = null;\n\n switch (typeCode) {\n case 10:\n case 11:\n scalarType = ScalarType.BOOLEAN;\n break;\n case 12:\n case 13:\n scalarType = ScalarType.INT_8;\n break;\n case 14:\n case 15:\n scalarType = ScalarType.UINT_8;\n break;\n case 16:\n case 17:\n scalarType = ScalarType.INT_32;\n break;\n case 18:\n case 19:\n scalarType = ScalarType.UINT_32;\n break;\n case 20:\n case 21:\n scalarType = ScalarType.INT_64;\n break;\n case 22:\n case 23:\n scalarType = ScalarType.UINT_64;\n break;\n case 24:\n case 25:\n scalarType = ScalarType.FLOAT;\n break;\n case 26:\n case 27:\n scalarType = ScalarType.DOUBLE;\n break;\n case 28:\n case 29:\n scalarType = ScalarType.STRING;\n break;\n default:\n return null;\n }\n\n const column = {} as Column;\n column.nullable = (typeCode & 1) !== 0;\n column.columnScope = ColumnScope.FEATURE;\n const scalarCol = {} as ScalarColumn;\n scalarCol.type = \"physicalType\";\n scalarCol.physicalType = scalarType;\n column.type = \"scalarType\";\n column.scalarType = scalarCol;\n return column;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"typeMap.js","sourceRoot":"","sources":["../../../src/metadata/tileset/typeMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,WAAW,EAEX,WAAW,EAEX,UAAU,GACb,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC7C,QAAQ,QAAQ,EAAE,CAAC;QACf,KAAK,CAAC,CAAC;QACP,KAAK,CAAC,CAAC;QACP,KAAK,CAAC,CAAC;QACP,KAAK,CAAC,CAAC,CAAC,CAAC;YACL,uEAAuE;YACvE,MAAM,MAAM,GAAG,EAAY,CAAC;YAC5B,MAAM,CAAC,QAAQ,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB;YAC5D,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;YACzC,MAAM,SAAS,GAAG,EAAkB,CAAC;YACrC,yEAAyE;YACzE,MAAM,YAAY,GAAG,QAAQ,GAAG,CAAC,CAA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AAC;QACR,KAAK,EAAE;YACH,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC;YAC9B,MAAM;QACV,KAAK,EAAE,CAAC;QACR,KAAK,EAAE;YACH,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC;YAC/B,MAAM;QACV,KAAK,EAAE,CAAC;QACR,KAAK,EAAE;YACH,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC;YAC/B,MAAM;QACV;YACI,OAAO,IAAI,CAAC;IACpB,CAAC;IAED,MAAM,MAAM,GAAG,EAAY,CAAC;IAC5B,MAAM,CAAC,QAAQ,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;IACzC,MAAM,SAAS,GAAG,EAAkB,CAAC;IACrC,SAAS,CAAC,IAAI,GAAG,cAAc,CAAC;IAChC,SAAS,CAAC,YAAY,GAAG,UAAU,CAAC;IACpC,MAAM,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import {\n type Column,\n ColumnScope,\n type ComplexColumn,\n ComplexType,\n type ScalarColumn,\n ScalarType,\n} from \"./tilesetMetadata\";\n\n/**\n * The type code is a single varint32 that encodes:\n * - Physical or logical type\n * - Nullable flag\n * - Whether the column has a name (typeCode >= 10)\n * - Whether the column has children (typeCode == 30 for STRUCT)\n * - For ID types: whether it uses long (64-bit) IDs\n */\n\n/**\n * Decodes a type code into a Column structure.\n * ID columns (0-3) are represented as physical UINT_32 or UINT_64 types in TypeScript\n */\nexport function decodeColumnType(typeCode: number): Column | null {\n switch (typeCode) {\n case 0:\n case 1:\n case 2:\n case 3: {\n // ID columns: 0=uint32, 1=uint64, 2=nullable uint32, 3=nullable uint64\n const column = {} as Column;\n column.nullable = (typeCode & 1) !== 0; // Bit 0 = nullable;\n column.columnScope = ColumnScope.FEATURE;\n const scalarCol = {} as ScalarColumn;\n // Map to physical type since TS schema doesn't have LogicalScalarType.ID\n const physicalType = typeCode > 1 ? ScalarType.UINT_64 : ScalarType.UINT_32; // Bit 1 = longID\n scalarCol.physicalType = physicalType;\n scalarCol.type = \"physicalType\";\n column.scalarType = scalarCol;\n column.type = \"scalarType\";\n return column;\n }\n case 4: {\n // GEOMETRY (non-nullable, no children)\n const column = {} as Column;\n column.nullable = false;\n column.columnScope = ColumnScope.FEATURE;\n const complexCol = {} as ComplexColumn;\n complexCol.type = \"physicalType\";\n complexCol.physicalType = ComplexType.GEOMETRY;\n column.type = \"complexType\";\n column.complexType = complexCol;\n return column;\n }\n case 30: {\n // STRUCT (non-nullable with children)\n const column = {} as Column;\n column.nullable = false;\n column.columnScope = ColumnScope.FEATURE;\n const complexCol = {} as ComplexColumn;\n complexCol.type = \"physicalType\";\n complexCol.physicalType = ComplexType.STRUCT;\n column.type = \"complexType\";\n column.complexType = complexCol;\n return column;\n }\n default:\n return mapScalarType(typeCode);\n }\n}\n\n/**\n * Returns true if this type code requires a name to be stored.\n * ID (0-3) and GEOMETRY (4) columns have implicit names.\n * All other types (>= 10) require explicit names.\n */\nexport function columnTypeHasName(typeCode: number): boolean {\n return typeCode >= 10;\n}\n\n/**\n * Returns true if this type code has child fields.\n * Only STRUCT (typeCode 30) has children.\n */\nexport function columnTypeHasChildren(typeCode: number): boolean {\n return typeCode === 30;\n}\n\n/**\n * Determines if a stream count needs to be read for this column.\n * Mirrors the logic in cpp/include/mlt/metadata/type_map.hpp lines 81-118\n */\nexport function hasStreamCount(column: Column): boolean {\n // ID columns don't have stream count (identified by name)\n if (column.name === \"id\") {\n return false;\n }\n\n if (column.type === \"scalarType\") {\n const scalarCol = column.scalarType;\n\n if (scalarCol.type === \"physicalType\") {\n const physicalType = scalarCol.physicalType;\n switch (physicalType) {\n case ScalarType.BOOLEAN:\n case ScalarType.INT_8:\n case ScalarType.UINT_8:\n case ScalarType.INT_32:\n case ScalarType.UINT_32:\n case ScalarType.INT_64:\n case ScalarType.UINT_64:\n case ScalarType.FLOAT:\n case ScalarType.DOUBLE:\n return false;\n case ScalarType.STRING:\n return true;\n default:\n return false;\n }\n } else if (scalarCol.type === \"logicalType\") {\n return false;\n }\n } else if (column.type === \"complexType\") {\n const complexCol = column.complexType;\n\n if (complexCol.type === \"physicalType\") {\n const physicalType = complexCol.physicalType;\n switch (physicalType) {\n case ComplexType.GEOMETRY:\n case ComplexType.STRUCT:\n return true;\n default:\n return false;\n }\n }\n }\n\n console.warn(\"Unexpected column type in hasStreamCount\", column);\n return false;\n}\n\n/**\n * Maps a scalar type code to a Column with ScalarType.\n * Type codes 10-29 encode scalar types with nullable flag.\n * Even codes are non-nullable, odd codes are nullable.\n */\nfunction mapScalarType(typeCode: number): Column | null {\n let scalarType: number | null = null;\n\n switch (typeCode) {\n case 10:\n case 11:\n scalarType = ScalarType.BOOLEAN;\n break;\n case 12:\n case 13:\n scalarType = ScalarType.INT_8;\n break;\n case 14:\n case 15:\n scalarType = ScalarType.UINT_8;\n break;\n case 16:\n case 17:\n scalarType = ScalarType.INT_32;\n break;\n case 18:\n case 19:\n scalarType = ScalarType.UINT_32;\n break;\n case 20:\n case 21:\n scalarType = ScalarType.INT_64;\n break;\n case 22:\n case 23:\n scalarType = ScalarType.UINT_64;\n break;\n case 24:\n case 25:\n scalarType = ScalarType.FLOAT;\n break;\n case 26:\n case 27:\n scalarType = ScalarType.DOUBLE;\n break;\n case 28:\n case 29:\n scalarType = ScalarType.STRING;\n break;\n default:\n return null;\n }\n\n const column = {} as Column;\n column.nullable = (typeCode & 1) !== 0;\n column.columnScope = ColumnScope.FEATURE;\n const scalarCol = {} as ScalarColumn;\n scalarCol.type = \"physicalType\";\n scalarCol.physicalType = scalarType;\n column.type = \"scalarType\";\n column.scalarType = scalarCol;\n return column;\n}\n"]}
|
package/dist/mltDecoder.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import FeatureTable from "./vector/featureTable";
|
|
2
2
|
import { ScalarType } from "./metadata/tileset/tilesetMetadata";
|
|
3
3
|
import IntWrapper from "./decoding/intWrapper";
|
|
4
|
-
import {
|
|
4
|
+
import { decodeStreamMetadata } from "./metadata/tile/streamMetadataDecoder";
|
|
5
5
|
import { VectorType } from "./vector/vectorType";
|
|
6
6
|
import { IntFlatVector } from "./vector/flat/intFlatVector";
|
|
7
7
|
import BitVector from "./vector/flat/bitVector";
|
|
@@ -17,7 +17,7 @@ import { LongConstVector } from "./vector/constant/longConstVector";
|
|
|
17
17
|
import { decodeBooleanRle } from "./decoding/decodingUtils";
|
|
18
18
|
import { DoubleFlatVector } from "./vector/flat/doubleFlatVector";
|
|
19
19
|
import { decodeEmbeddedTileSetMetadata } from "./metadata/tileset/embeddedTilesetMetadataDecoder";
|
|
20
|
-
import {
|
|
20
|
+
import { hasStreamCount } from "./metadata/tileset/typeMap";
|
|
21
21
|
const ID_COLUMN_NAME = "id";
|
|
22
22
|
const GEOMETRY_COLUMN_NAME = "geometry";
|
|
23
23
|
/**
|
|
@@ -60,15 +60,15 @@ export default function decodeTile(tile, geometryScaling, idWithinMaxSafeInteger
|
|
|
60
60
|
let nullabilityBuffer = null;
|
|
61
61
|
// Check column metadata nullable flag, not numStreams (ID columns don't have stream count)
|
|
62
62
|
if (columnMetadata.nullable) {
|
|
63
|
-
const presentStreamMetadata =
|
|
63
|
+
const presentStreamMetadata = decodeStreamMetadata(tile, offset);
|
|
64
64
|
const streamDataStart = offset.get();
|
|
65
65
|
const values = decodeBooleanRle(tile, presentStreamMetadata.numValues, offset);
|
|
66
66
|
// Fix offset: decodeBooleanRle doesn't consume all compressed bytes
|
|
67
67
|
offset.set(streamDataStart + presentStreamMetadata.byteLength);
|
|
68
68
|
nullabilityBuffer = new BitVector(values, presentStreamMetadata.numValues);
|
|
69
69
|
}
|
|
70
|
-
const idDataStreamMetadata =
|
|
71
|
-
numFeatures = idDataStreamMetadata.
|
|
70
|
+
const idDataStreamMetadata = decodeStreamMetadata(tile, offset);
|
|
71
|
+
numFeatures = idDataStreamMetadata.decompressedCount;
|
|
72
72
|
idVector = decodeIdColumn(tile, columnMetadata, offset, columnName, idDataStreamMetadata, nullabilityBuffer ?? numFeatures, idWithinMaxSafeInteger);
|
|
73
73
|
}
|
|
74
74
|
else if (columnName === GEOMETRY_COLUMN_NAME) {
|
|
@@ -76,8 +76,8 @@ export default function decodeTile(tile, geometryScaling, idWithinMaxSafeInteger
|
|
|
76
76
|
// If no ID column, get numFeatures from geometry type stream metadata
|
|
77
77
|
if (numFeatures === 0) {
|
|
78
78
|
const savedOffset = offset.get();
|
|
79
|
-
const geometryTypeMetadata =
|
|
80
|
-
numFeatures = geometryTypeMetadata.
|
|
79
|
+
const geometryTypeMetadata = decodeStreamMetadata(tile, offset);
|
|
80
|
+
numFeatures = geometryTypeMetadata.decompressedCount;
|
|
81
81
|
offset.set(savedOffset); // Reset to re-read in decodeGeometryColumn
|
|
82
82
|
}
|
|
83
83
|
if (geometryScaling) {
|
|
@@ -87,7 +87,7 @@ export default function decodeTile(tile, geometryScaling, idWithinMaxSafeInteger
|
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
// Property columns: STRING and STRUCT have stream count, others don't
|
|
90
|
-
const hasStreamCnt =
|
|
90
|
+
const hasStreamCnt = hasStreamCount(columnMetadata);
|
|
91
91
|
const numStreams = hasStreamCnt ? decodeVarintInt32(tile, offset, 1)[0] : 1;
|
|
92
92
|
if (numStreams === 0 && columnMetadata.type === "scalarType") {
|
|
93
93
|
continue;
|
|
@@ -95,7 +95,9 @@ export default function decodeTile(tile, geometryScaling, idWithinMaxSafeInteger
|
|
|
95
95
|
const propertyVector = decodePropertyColumn(tile, offset, columnMetadata, numStreams, numFeatures, undefined);
|
|
96
96
|
if (propertyVector) {
|
|
97
97
|
if (Array.isArray(propertyVector)) {
|
|
98
|
-
|
|
98
|
+
for (const property of propertyVector) {
|
|
99
|
+
propertyVectors.push(property);
|
|
100
|
+
}
|
|
99
101
|
}
|
|
100
102
|
else {
|
|
101
103
|
propertyVectors.push(propertyVector);
|
package/dist/mltDecoder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mltDecoder.js","sourceRoot":"","sources":["../src/mltDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAe,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACH,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC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C,CAAC;gBAC5E,OAAO,IAAI,eAAe,CAAC,UAAU,EAAE,EAAE,EAAE,uBAAuB,CAAC,CAAC;YACxE,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import FeatureTable from \"./vector/featureTable\";\nimport { type Column, ScalarType } from \"./metadata/tileset/tilesetMetadata\";\nimport IntWrapper from \"./decoding/intWrapper\";\nimport { StreamMetadataDecoder } from \"./metadata/tile/streamMetadataDecoder\";\nimport { type RleEncodedStreamMetadata } from \"./metadata/tile/rleEncodedStreamMetadata\";\nimport { VectorType } from \"./vector/vectorType\";\nimport { IntFlatVector } from \"./vector/flat/intFlatVector\";\nimport BitVector from \"./vector/flat/bitVector\";\nimport {\n decodeConstIntStream,\n decodeConstLongStream,\n decodeIntStream,\n decodeLongFloat64Stream,\n decodeLongStream,\n decodeSequenceIntStream,\n decodeSequenceLongStream,\n getVectorType,\n} from \"./decoding/integerStreamDecoder\";\nimport { IntSequenceVector } from \"./vector/sequence/intSequenceVector\";\nimport { LongFlatVector } from \"./vector/flat/longFlatVector\";\nimport { LongSequenceVector } from \"./vector/sequence/longSequenceVector\";\nimport { type IntVector } from \"./vector/intVector\";\nimport { decodeVarintInt32 } from \"./decoding/integerDecodingUtils\";\nimport { decodeGeometryColumn } from \"./decoding/geometryDecoder\";\nimport { decodePropertyColumn } from \"./decoding/propertyDecoder\";\nimport { IntConstVector } from \"./vector/constant/intConstVector\";\nimport { LongConstVector } from \"./vector/constant/longConstVector\";\nimport type GeometryScaling from \"./decoding/geometryScaling\";\nimport { decodeBooleanRle } from \"./decoding/decodingUtils\";\nimport { DoubleFlatVector } from \"./vector/flat/doubleFlatVector\";\nimport { decodeEmbeddedTileSetMetadata } from \"./metadata/tileset/embeddedTilesetMetadataDecoder\";\nimport { TypeMap } from \"./metadata/tileset/typeMap\";\nimport { type StreamMetadata } from \"./metadata/tile/streamMetadata\";\nimport { type GeometryVector } from \"./vector/geometry/geometryVector\";\nimport type Vector from \"./vector/vector\";\nimport { type GpuVector } from \"./vector/geometry/gpuVector\";\n\nconst ID_COLUMN_NAME = \"id\";\nconst GEOMETRY_COLUMN_NAME = \"geometry\";\n\n/**\n * Decodes a tile with embedded metadata (Tag 0x01 format).\n * This is the primary decoder function for MLT tiles.\n *\n * @param tile The tile data to decode (will be decompressed if gzip-compressed)\n * @param geometryScaling Optional geometry scaling parameters\n * @param idWithinMaxSafeInteger If true, limits ID values to JavaScript safe integer range (53 bits)\n */\nexport default function decodeTile(\n tile: Uint8Array,\n geometryScaling?: GeometryScaling,\n idWithinMaxSafeInteger = true,\n): FeatureTable[] {\n const offset = new IntWrapper(0);\n const featureTables: FeatureTable[] = [];\n\n while (offset.get() < tile.length) {\n const blockLength = decodeVarintInt32(tile, offset, 1)[0] >>> 0;\n const blockStart = offset.get();\n const blockEnd = blockStart + blockLength;\n if (blockEnd > tile.length) {\n throw new Error(`Block overruns tile: ${blockEnd} > ${tile.length}`);\n }\n\n const tag = decodeVarintInt32(tile, offset, 1)[0] >>> 0;\n if (tag !== 1) {\n // Skip unknown block types\n offset.set(blockEnd);\n continue;\n }\n\n // Decode embedded metadata and extent (one of each per block)\n const decode = decodeEmbeddedTileSetMetadata(tile, offset);\n const metadata = decode[0];\n const extent = decode[1];\n const featureTableMetadata = metadata.featureTables[0];\n\n // Decode columns from streams\n let idVector: IntVector | null = null;\n let geometryVector: GeometryVector | GpuVector | null = null;\n const propertyVectors: Vector[] = [];\n let numFeatures = 0;\n\n for (const columnMetadata of featureTableMetadata.columns) {\n const columnName = columnMetadata.name;\n\n if (columnName === ID_COLUMN_NAME) {\n let nullabilityBuffer = null;\n // Check column metadata nullable flag, not numStreams (ID columns don't have stream count)\n if (columnMetadata.nullable) {\n const presentStreamMetadata = StreamMetadataDecoder.decode(tile, offset);\n const streamDataStart = offset.get();\n const values = decodeBooleanRle(tile, presentStreamMetadata.numValues, offset);\n // Fix offset: decodeBooleanRle doesn't consume all compressed bytes\n offset.set(streamDataStart + presentStreamMetadata.byteLength);\n nullabilityBuffer = new BitVector(values, presentStreamMetadata.numValues);\n }\n\n const idDataStreamMetadata = StreamMetadataDecoder.decode(tile, offset);\n numFeatures = idDataStreamMetadata.getDecompressedCount();\n\n idVector = decodeIdColumn(\n tile,\n columnMetadata,\n offset,\n columnName,\n idDataStreamMetadata,\n nullabilityBuffer ?? numFeatures,\n idWithinMaxSafeInteger,\n );\n } else if (columnName === GEOMETRY_COLUMN_NAME) {\n const numStreams = decodeVarintInt32(tile, offset, 1)[0];\n\n // If no ID column, get numFeatures from geometry type stream metadata\n if (numFeatures === 0) {\n const savedOffset = offset.get();\n const geometryTypeMetadata = StreamMetadataDecoder.decode(tile, offset);\n numFeatures = geometryTypeMetadata.getDecompressedCount();\n offset.set(savedOffset); // Reset to re-read in decodeGeometryColumn\n }\n\n if (geometryScaling) {\n geometryScaling.scale = geometryScaling.extent / extent;\n }\n\n geometryVector = decodeGeometryColumn(tile, numStreams, offset, numFeatures, geometryScaling);\n } else {\n // Property columns: STRING and STRUCT have stream count, others don't\n const hasStreamCnt = TypeMap.hasStreamCount(columnMetadata);\n const numStreams = hasStreamCnt ? decodeVarintInt32(tile, offset, 1)[0] : 1;\n\n if (numStreams === 0 && columnMetadata.type === \"scalarType\") {\n continue;\n }\n\n const propertyVector = decodePropertyColumn(\n tile,\n offset,\n columnMetadata,\n numStreams,\n numFeatures,\n undefined,\n );\n if (propertyVector) {\n if (Array.isArray(propertyVector)) {\n propertyVectors.push(...propertyVector);\n } else {\n propertyVectors.push(propertyVector);\n }\n }\n }\n }\n\n const featureTable = new FeatureTable(\n featureTableMetadata.name,\n geometryVector,\n idVector,\n propertyVectors,\n extent,\n );\n featureTables.push(featureTable);\n offset.set(blockEnd);\n }\n\n return featureTables;\n}\n\nfunction decodeIdColumn(\n tile: Uint8Array,\n columnMetadata: Column,\n offset: IntWrapper,\n columnName: string,\n idDataStreamMetadata: StreamMetadata,\n sizeOrNullabilityBuffer: number | BitVector,\n idWithinMaxSafeInteger: boolean = false,\n): IntVector {\n const idDataType = columnMetadata.scalarType.physicalType;\n const vectorType = getVectorType(idDataStreamMetadata, sizeOrNullabilityBuffer, tile, offset);\n if (idDataType === ScalarType.UINT_32) {\n switch (vectorType) {\n case VectorType.FLAT: {\n const id = decodeIntStream(tile, offset, idDataStreamMetadata, false);\n return new IntFlatVector(columnName, id, sizeOrNullabilityBuffer);\n }\n case VectorType.SEQUENCE: {\n const id = decodeSequenceIntStream(tile, offset, idDataStreamMetadata);\n return new IntSequenceVector(\n columnName,\n id[0],\n id[1],\n (idDataStreamMetadata as RleEncodedStreamMetadata).numRleValues,\n );\n }\n case VectorType.CONST: {\n const id = decodeConstIntStream(tile, offset, idDataStreamMetadata, false);\n return new IntConstVector(columnName, id, sizeOrNullabilityBuffer);\n }\n }\n } else {\n switch (vectorType) {\n case VectorType.FLAT: {\n if (idWithinMaxSafeInteger) {\n const id = decodeLongFloat64Stream(tile, offset, idDataStreamMetadata, false);\n return new DoubleFlatVector(columnName, id, sizeOrNullabilityBuffer);\n }\n\n const id = decodeLongStream(tile, offset, idDataStreamMetadata, false);\n return new LongFlatVector(columnName, id, sizeOrNullabilityBuffer);\n }\n case VectorType.SEQUENCE: {\n const id = decodeSequenceLongStream(tile, offset, idDataStreamMetadata);\n return new LongSequenceVector(\n columnName,\n id[0],\n id[1],\n (idDataStreamMetadata as RleEncodedStreamMetadata).numRleValues,\n );\n }\n case VectorType.CONST: {\n const id = decodeConstLongStream(tile, offset, idDataStreamMetadata, false);\n return new LongConstVector(columnName, id, sizeOrNullabilityBuffer);\n }\n }\n }\n\n throw new Error(\"Vector type not supported for id column.\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mltDecoder.js","sourceRoot":"","sources":["../src/mltDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAe,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAC7E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AAC;YACvE,CAAC;QACL,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,QAAQ,UAAU,EAAE,CAAC;YACjB,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;gBACnB,IAAI,sBAAsB,EAAE,CAAC;oBACzB,MAAM,EAAE,GAAG,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;oBAC9E,OAAO,IAAI,gBAAgB,CAAC,UAAU,EAAE,EAAE,EAAE,uBAAuB,CAAC,CAAC;gBACzE,CAAC;gBAED,MAAM,EAAE,GAAG,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;gBACvE,OAAO,IAAI,cAAc,CAAC,UAAU,EAAE,EAAE,EAAE,uBAAuB,CAAC,CAAC;YACvE,CAAC;YACD,KAAK,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACvB,MAAM,EAAE,GAAG,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC;gBACxE,OAAO,IAAI,kBAAkB,CACzB,UAAU,EACV,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,EACJ,oBAAiD,CAAC,YAAY,CAClE,CAAC;YACN,CAAC;YACD,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;gBACpB,MAAM,EAAE,GAAG,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;gBAC5E,OAAO,IAAI,eAAe,CAAC,UAAU,EAAE,EAAE,EAAE,uBAAuB,CAAC,CAAC;YACxE,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import FeatureTable from \"./vector/featureTable\";\nimport { type Column, ScalarType } from \"./metadata/tileset/tilesetMetadata\";\nimport IntWrapper from \"./decoding/intWrapper\";\nimport { decodeStreamMetadata, type RleEncodedStreamMetadata } from \"./metadata/tile/streamMetadataDecoder\";\nimport { VectorType } from \"./vector/vectorType\";\nimport { IntFlatVector } from \"./vector/flat/intFlatVector\";\nimport BitVector from \"./vector/flat/bitVector\";\nimport {\n decodeConstIntStream,\n decodeConstLongStream,\n decodeIntStream,\n decodeLongFloat64Stream,\n decodeLongStream,\n decodeSequenceIntStream,\n decodeSequenceLongStream,\n getVectorType,\n} from \"./decoding/integerStreamDecoder\";\nimport { IntSequenceVector } from \"./vector/sequence/intSequenceVector\";\nimport { LongFlatVector } from \"./vector/flat/longFlatVector\";\nimport { LongSequenceVector } from \"./vector/sequence/longSequenceVector\";\nimport { type IntVector } from \"./vector/intVector\";\nimport { decodeVarintInt32 } from \"./decoding/integerDecodingUtils\";\nimport { decodeGeometryColumn } from \"./decoding/geometryDecoder\";\nimport { decodePropertyColumn } from \"./decoding/propertyDecoder\";\nimport { IntConstVector } from \"./vector/constant/intConstVector\";\nimport { LongConstVector } from \"./vector/constant/longConstVector\";\nimport type GeometryScaling from \"./decoding/geometryScaling\";\nimport { decodeBooleanRle } from \"./decoding/decodingUtils\";\nimport { DoubleFlatVector } from \"./vector/flat/doubleFlatVector\";\nimport { decodeEmbeddedTileSetMetadata } from \"./metadata/tileset/embeddedTilesetMetadataDecoder\";\nimport { hasStreamCount } from \"./metadata/tileset/typeMap\";\nimport { type StreamMetadata } from \"./metadata/tile/streamMetadataDecoder\";\nimport { type GeometryVector } from \"./vector/geometry/geometryVector\";\nimport type Vector from \"./vector/vector\";\nimport { type GpuVector } from \"./vector/geometry/gpuVector\";\n\nconst ID_COLUMN_NAME = \"id\";\nconst GEOMETRY_COLUMN_NAME = \"geometry\";\n\n/**\n * Decodes a tile with embedded metadata (Tag 0x01 format).\n * This is the primary decoder function for MLT tiles.\n *\n * @param tile The tile data to decode (will be decompressed if gzip-compressed)\n * @param geometryScaling Optional geometry scaling parameters\n * @param idWithinMaxSafeInteger If true, limits ID values to JavaScript safe integer range (53 bits)\n */\nexport default function decodeTile(\n tile: Uint8Array,\n geometryScaling?: GeometryScaling,\n idWithinMaxSafeInteger = true,\n): FeatureTable[] {\n const offset = new IntWrapper(0);\n const featureTables: FeatureTable[] = [];\n\n while (offset.get() < tile.length) {\n const blockLength = decodeVarintInt32(tile, offset, 1)[0] >>> 0;\n const blockStart = offset.get();\n const blockEnd = blockStart + blockLength;\n if (blockEnd > tile.length) {\n throw new Error(`Block overruns tile: ${blockEnd} > ${tile.length}`);\n }\n\n const tag = decodeVarintInt32(tile, offset, 1)[0] >>> 0;\n if (tag !== 1) {\n // Skip unknown block types\n offset.set(blockEnd);\n continue;\n }\n\n // Decode embedded metadata and extent (one of each per block)\n const decode = decodeEmbeddedTileSetMetadata(tile, offset);\n const metadata = decode[0];\n const extent = decode[1];\n const featureTableMetadata = metadata.featureTables[0];\n\n // Decode columns from streams\n let idVector: IntVector | null = null;\n let geometryVector: GeometryVector | GpuVector | null = null;\n const propertyVectors: Vector[] = [];\n let numFeatures = 0;\n\n for (const columnMetadata of featureTableMetadata.columns) {\n const columnName = columnMetadata.name;\n\n if (columnName === ID_COLUMN_NAME) {\n let nullabilityBuffer = null;\n // Check column metadata nullable flag, not numStreams (ID columns don't have stream count)\n if (columnMetadata.nullable) {\n const presentStreamMetadata = decodeStreamMetadata(tile, offset);\n const streamDataStart = offset.get();\n const values = decodeBooleanRle(tile, presentStreamMetadata.numValues, offset);\n // Fix offset: decodeBooleanRle doesn't consume all compressed bytes\n offset.set(streamDataStart + presentStreamMetadata.byteLength);\n nullabilityBuffer = new BitVector(values, presentStreamMetadata.numValues);\n }\n\n const idDataStreamMetadata = decodeStreamMetadata(tile, offset);\n numFeatures = idDataStreamMetadata.decompressedCount;\n\n idVector = decodeIdColumn(\n tile,\n columnMetadata,\n offset,\n columnName,\n idDataStreamMetadata,\n nullabilityBuffer ?? numFeatures,\n idWithinMaxSafeInteger,\n );\n } else if (columnName === GEOMETRY_COLUMN_NAME) {\n const numStreams = decodeVarintInt32(tile, offset, 1)[0];\n\n // If no ID column, get numFeatures from geometry type stream metadata\n if (numFeatures === 0) {\n const savedOffset = offset.get();\n const geometryTypeMetadata = decodeStreamMetadata(tile, offset);\n numFeatures = geometryTypeMetadata.decompressedCount;\n offset.set(savedOffset); // Reset to re-read in decodeGeometryColumn\n }\n\n if (geometryScaling) {\n geometryScaling.scale = geometryScaling.extent / extent;\n }\n\n geometryVector = decodeGeometryColumn(tile, numStreams, offset, numFeatures, geometryScaling);\n } else {\n // Property columns: STRING and STRUCT have stream count, others don't\n const hasStreamCnt = hasStreamCount(columnMetadata);\n const numStreams = hasStreamCnt ? decodeVarintInt32(tile, offset, 1)[0] : 1;\n\n if (numStreams === 0 && columnMetadata.type === \"scalarType\") {\n continue;\n }\n\n const propertyVector = decodePropertyColumn(\n tile,\n offset,\n columnMetadata,\n numStreams,\n numFeatures,\n undefined,\n );\n if (propertyVector) {\n if (Array.isArray(propertyVector)) {\n for (const property of propertyVector) {\n propertyVectors.push(property);\n }\n } else {\n propertyVectors.push(propertyVector);\n }\n }\n }\n }\n\n const featureTable = new FeatureTable(\n featureTableMetadata.name,\n geometryVector,\n idVector,\n propertyVectors,\n extent,\n );\n featureTables.push(featureTable);\n offset.set(blockEnd);\n }\n\n return featureTables;\n}\n\nfunction decodeIdColumn(\n tile: Uint8Array,\n columnMetadata: Column,\n offset: IntWrapper,\n columnName: string,\n idDataStreamMetadata: StreamMetadata,\n sizeOrNullabilityBuffer: number | BitVector,\n idWithinMaxSafeInteger: boolean = false,\n): IntVector {\n const idDataType = columnMetadata.scalarType.physicalType;\n const vectorType = getVectorType(idDataStreamMetadata, sizeOrNullabilityBuffer, tile, offset);\n if (idDataType === ScalarType.UINT_32) {\n switch (vectorType) {\n case VectorType.FLAT: {\n const id = decodeIntStream(tile, offset, idDataStreamMetadata, false);\n return new IntFlatVector(columnName, id, sizeOrNullabilityBuffer);\n }\n case VectorType.SEQUENCE: {\n const id = decodeSequenceIntStream(tile, offset, idDataStreamMetadata);\n return new IntSequenceVector(\n columnName,\n id[0],\n id[1],\n (idDataStreamMetadata as RleEncodedStreamMetadata).numRleValues,\n );\n }\n case VectorType.CONST: {\n const id = decodeConstIntStream(tile, offset, idDataStreamMetadata, false);\n return new IntConstVector(columnName, id, sizeOrNullabilityBuffer);\n }\n }\n } else {\n switch (vectorType) {\n case VectorType.FLAT: {\n if (idWithinMaxSafeInteger) {\n const id = decodeLongFloat64Stream(tile, offset, idDataStreamMetadata, false);\n return new DoubleFlatVector(columnName, id, sizeOrNullabilityBuffer);\n }\n\n const id = decodeLongStream(tile, offset, idDataStreamMetadata, false);\n return new LongFlatVector(columnName, id, sizeOrNullabilityBuffer);\n }\n case VectorType.SEQUENCE: {\n const id = decodeSequenceLongStream(tile, offset, idDataStreamMetadata);\n return new LongSequenceVector(\n columnName,\n id[0],\n id[1],\n (idDataStreamMetadata as RleEncodedStreamMetadata).numRleValues,\n );\n }\n case VectorType.CONST: {\n const id = decodeConstLongStream(tile, offset, idDataStreamMetadata, false);\n return new LongConstVector(columnName, id, sizeOrNullabilityBuffer);\n }\n }\n }\n\n throw new Error(\"Vector type not supported for id column.\");\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { convertGeometryVector } from "./geometryVectorConverter";
|
|
2
|
-
import
|
|
2
|
+
import { decodeZOrderCurve } from "./zOrderCurve";
|
|
3
3
|
export class GeometryVector {
|
|
4
4
|
_vertexBufferType;
|
|
5
5
|
_topologyVector;
|
|
@@ -48,7 +48,7 @@ export class GeometryVector {
|
|
|
48
48
|
const vertexOffset = this.vertexOffsets[index];
|
|
49
49
|
const mortonEncodedVertex = this.vertexBuffer[vertexOffset];
|
|
50
50
|
//TODO: improve performance -> inline calculation and move to decoding of VertexBuffer
|
|
51
|
-
const vertex =
|
|
51
|
+
const vertex = decodeZOrderCurve(mortonEncodedVertex, this.mortonSettings.numBits, this.mortonSettings.coordinateShift);
|
|
52
52
|
return [vertex.x, vertex.y];
|
|
53
53
|
}
|
|
54
54
|
const offset = this.vertexOffsets ? this.vertexOffsets[index] * 2 : index * 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometryVector.js","sourceRoot":"","sources":["../../../src/vector/geometry/geometryVector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"geometryVector.js","sourceRoot":"","sources":["../../../src/vector/geometry/geometryVector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAiBlD,MAAM,OAAgB,cAAc;IAEX;IACA;IACA;IACA;IACA;IALrB,YACqB,iBAAmC,EACnC,eAA+B,EAC/B,cAA0B,EAC1B,aAAyB,EACzB,eAAgC;QAJhC,sBAAiB,GAAjB,iBAAiB,CAAkB;QACnC,oBAAe,GAAf,eAAe,CAAgB;QAC/B,mBAAc,GAAd,cAAc,CAAY;QAC1B,kBAAa,GAAb,aAAa,CAAY;QACzB,oBAAe,GAAf,eAAe,CAAiB;IAClD,CAAC;IAEJ,IAAI,gBAAgB;QAChB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAClC,CAAC;IAED,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IACD,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QACd,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,OAAO,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YAChC,MAAM,EAAE,WAAW,EAAE,U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C;QACpC,MAAM,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,aAAa;QACT,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;CASJ","sourcesContent":["import type TopologyVector from \"../../vector/geometry/topologyVector\";\nimport { convertGeometryVector } from \"./geometryVectorConverter\";\nimport { decodeZOrderCurve } from \"./zOrderCurve\";\nimport { type GEOMETRY_TYPE } from \"./geometryType\";\nimport { type VertexBufferType } from \"./vertexBufferType\";\nimport type Point from \"@mapbox/point-geometry\";\n\nexport type CoordinatesArray = Array<Array<Point>>;\n\nexport type Geometry = {\n coordinates: CoordinatesArray;\n type: GEOMETRY_TYPE;\n};\n\nexport interface MortonSettings {\n numBits: number;\n coordinateShift: number;\n}\n\nexport abstract class GeometryVector implements Iterable<Geometry> {\n protected constructor(\n private readonly _vertexBufferType: VertexBufferType,\n private readonly _topologyVector: TopologyVector,\n private readonly _vertexOffsets: Int32Array,\n private readonly _vertexBuffer: Int32Array,\n private readonly _mortonSettings?: MortonSettings,\n ) {}\n\n get vertexBufferType(): VertexBufferType {\n return this._vertexBufferType;\n }\n\n get topologyVector(): TopologyVector {\n return this._topologyVector;\n }\n\n get vertexOffsets(): Int32Array {\n return this._vertexOffsets;\n }\n\n get vertexBuffer(): Int32Array {\n return this._vertexBuffer;\n }\n *[Symbol.iterator](): Iterator<Geometry> {\n const geometries = convertGeometryVector(this);\n let index = 0;\n\n while (index < this.numGeometries) {\n yield { coordinates: geometries[index], type: this.geometryType(index) };\n index++;\n }\n }\n\n /* Allows faster access to the vertices since morton encoding is currently not used in the POC. Morton encoding\n will be used after adapting the shader to decode the morton codes on the GPU. */\n getSimpleEncodedVertex(index: number): [number, number] {\n const offset = this.vertexOffsets ? this.vertexOffsets[index] * 2 : index * 2;\n const x = this.vertexBuffer[offset];\n const y = this.vertexBuffer[offset + 1];\n return [x, y];\n }\n\n //TODO: add scaling information to the constructor\n getVertex(index: number): [number, number] {\n if (this.vertexOffsets && this.mortonSettings) {\n //TODO: move decoding of the morton codes on the GPU in the vertex shader\n const vertexOffset = this.vertexOffsets[index];\n const mortonEncodedVertex = this.vertexBuffer[vertexOffset];\n //TODO: improve performance -> inline calculation and move to decoding of VertexBuffer\n const vertex = decodeZOrderCurve(\n mortonEncodedVertex,\n this.mortonSettings.numBits,\n this.mortonSettings.coordinateShift,\n );\n return [vertex.x, vertex.y];\n }\n\n const offset = this.vertexOffsets ? this.vertexOffsets[index] * 2 : index * 2;\n const x = this.vertexBuffer[offset];\n const y = this.vertexBuffer[offset + 1];\n return [x, y];\n }\n\n getGeometries(): CoordinatesArray[] {\n return convertGeometryVector(this);\n }\n\n get mortonSettings(): MortonSettings | undefined {\n return this._mortonSettings;\n }\n\n abstract containsPolygonGeometry(): boolean;\n\n abstract geometryType(index: number): number;\n\n abstract get numGeometries(): number;\n\n abstract containsSingleGeometryType(): boolean;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { decodeZOrderCurve } from "./zOrderCurve";
|
|
2
2
|
import { GEOMETRY_TYPE } from "./geometryType";
|
|
3
3
|
import { VertexBufferType } from "./vertexBufferType";
|
|
4
4
|
import Point from "@mapbox/point-geometry";
|
|
@@ -16,7 +16,7 @@ class MvtGeometryFactory {
|
|
|
16
16
|
return lineStrings;
|
|
17
17
|
}
|
|
18
18
|
createPolygon(shell, rings) {
|
|
19
|
-
return [shell
|
|
19
|
+
return [shell].concat(rings);
|
|
20
20
|
}
|
|
21
21
|
createMultiPolygon(polygons) {
|
|
22
22
|
//TODO: check winding order of shell and holes
|
|
@@ -59,7 +59,7 @@ export function convertGeometryVector(geometryVector) {
|
|
|
59
59
|
else {
|
|
60
60
|
const offset = vertexOffsets[vertexOffsetsOffset++];
|
|
61
61
|
const mortonCode = vertexBuffer[offset];
|
|
62
|
-
const vertex =
|
|
62
|
+
const vertex = decodeZOrderCurve(mortonCode, mortonSettings.numBits, mortonSettings.coordinateShift);
|
|
63
63
|
const coordinate = new Point(vertex.x, vertex.y);
|
|
64
64
|
geometries[geometryCounter++] = geometryFactory.createPoint(coordinate);
|
|
65
65
|
}
|
|
@@ -288,7 +288,7 @@ function decodeMortonDictionaryEncodedLineString(vertexBuffer, vertexOffsets, ve
|
|
|
288
288
|
for (let i = 0; i < numVertices; i++) {
|
|
289
289
|
const offset = vertexOffsets[vertexOffset + i];
|
|
290
290
|
const mortonEncodedVertex = vertexBuffer[offset];
|
|
291
|
-
const vertex =
|
|
291
|
+
const vertex = decodeZOrderCurve(mortonEncodedVertex, mortonSettings.numBits, mortonSettings.coordinateShift);
|
|
292
292
|
vertices[i] = new Point(vertex.x, vertex.y);
|
|
293
293
|
}
|
|
294
294
|
if (closeLineString) {
|