Standardize metadata type handling in `VoxelProvider`
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
`VoxelProvider` is inconsistent with the rest of the repo in the way it handles metadata properties.
Metadata properties are specified in the tileset.json / schema.json as a list of objects:
```json
"properties": {
"property1": {
"type": "SCALAR",
"componentType": "FLOAT32"
},
"property2": {
"type": "VEC2",
"componentType": "FLOAT32"
}
}
```
But in `VoxelProvider` these are flattened into arrays, as follows:
```javascript
/**
* Gets the metadata names.
*
* @type {string[]}
* @readonly
* @constant
*/
names;
/**
* Gets the metadata types.
*
* @type {MetadataType[]}
* @readonly
* @constant
*/
types;
/**
* Gets the metadata component types.
*
* @type {MetadataComponentType[]}
* @readonly
* @constant
*/
componentTypes;
```
While this structure may initially have been chosen for performance reasons, in the current code we only loop over properties once when loading a `VoxelProvider`, so performance benefits (if any) are minimal. Meanwhile, the flattened array pattern adds complexity in a few places:
- Looping over properties: we have to look up the name, type, and componentType of each property separately, assuming/hoping that the indices are consistent
- TS/JSDoc documentation for internal functions: a helper function that loops over properties has an awkward return type. See `getAttributeInfo` in `Cesium3DTilesVoxelProvider`:
```javascript
return {
className,
names,
types,
componentTypes,
minimumValues: hasMinimumValues ? minimumValues : undefined,
maximumValues: hasMinimumValues ? maximumValues : undefined,
};
```
As part of https://github.com/CesiumGS/cesium/issues/12297 we should simplify and improve documentation by using lists of property info objects, following the pattern of the metadata schema.
Contributor guide
Assessment
This issue has not been assessed yet.