Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

fix(table): preserve vector field names with literal pipes (#3967)

Igor Dykhta0b3ac13b6386
diff --git a/src/table/src/tileset/vector-tile-utils.spec.ts b/src/table/src/tileset/vector-tile-utils.spec.ts
index 32943b3f5..d4ea2ffde 100644
--- a/src/table/src/tileset/vector-tile-utils.spec.ts
+++ b/src/table/src/tileset/vector-tile-utils.spec.ts
@@ -197,6 +197,59 @@ test.each([
}
);
+test.each(['air|quality', 'value|'])(
+ 'parseMetadata preserves the literal non-date field %s',
+ name => {
+ const metadata = parseMetadata({
+ tilejson: {
+ layers: [{id: 'features', fields: [{name, type: 'int', min: 0, max: 10}]}]
+ }
+ } as any);
+ expect(metadata?.fields).toHaveLength(1);
+ expect(metadata?.fields[0]).toMatchObject({
+ name,
+ id: name,
+ type: ALL_FIELD_TYPES.integer
+ });
+ expect(metadata?.fields[0].filterProps?.domain?.slice()).toEqual([0, 10]);
+ expect(metadata?.fields[0]).not.toHaveProperty('indexBy');
+ }
+);
+
+test('parseMetadata keeps literal pipe fields alongside ordinary and dated fields', () => {
+ const metadata = parseMetadata({
+ tilejson: {
+ layers: [
+ {
+ id: 'features',
+ fields: [
+ {name: 'ordinary', type: 'int', min: 0, max: 10},
+ {name: 'value|', type: 'int', min: 1, max: 2},
+ {name: 'value|quality', type: 'int', min: 3, max: 4},
+ {name: 'value|2020-01-01', type: 'int', min: 5, max: 6},
+ {name: 'value|2021-01-01', type: 'int', min: 7, max: 8}
+ ]
+ }
+ ]
+ }
+ } as any);
+ expect(metadata?.fields.map(field => field.name)).toEqual([
+ 'ordinary',
+ 'value',
+ 'value|',
+ 'value|quality'
+ ]);
+ expect(metadata?.fields.find(field => field.name === 'value')).toMatchObject({
+ indexBy: {
+ type: ALL_FIELD_TYPES.date,
+ mappedValue: {
+ [Date.UTC(2020, 0, 1)]: 'value|2020-01-01',
+ [Date.UTC(2021, 0, 1)]: 'value|2021-01-01'
+ }
+ }
+ });
+});
+
test.each([
['int', [7]],
['int', ['7']],
diff --git a/src/table/src/tileset/vector-tile-utils.ts b/src/table/src/tileset/vector-tile-utils.ts
index 350f4bc88..47809c799 100644
--- a/src/table/src/tileset/vector-tile-utils.ts
+++ b/src/table/src/tileset/vector-tile-utils.ts
@@ -429,7 +429,9 @@ function collectAttributes(layers: TippecanoeLayer[] = []): VectorTileField[] {
// parse indexed attribute, and put index key unidentified back as normal field
for (const [name, attrs] of Object.entries(indexedAttributes)) {
const {indexedField, unidentified} = parseIndexedField(name, attrs);
- fields[indexedField.name] = indexedField;
+ if (indexedField) {
+ fields[indexedField.name] = indexedField;
+ }
for (const unidentifiedAttr of unidentified) {
if (unidentifiedAttr.attribute) {
fields[unidentifiedAttr.attribute] =
@@ -459,7 +461,7 @@ function parseIndexedField(
attrs: TippecanoeLayerAttribute[]
): {
unidentified: TippecanoeLayerAttribute[];
- indexedField: VectorTileField;
+ indexedField: VectorTileField | undefined;
} {
const unidentified: TippecanoeLayerAttribute[] = [];
// analyze time format
@@ -497,7 +499,7 @@ function parseIndexedField(
}
}
- if (field.indexBy && field.indexBy.type === ALL_FIELD_TYPES.timestamp) {
+ if (field?.indexBy && field.indexBy.type === ALL_FIELD_TYPES.timestamp) {
field.indexBy.timeDomain = getTimeAnimationDomain(
Object.keys(field.indexBy.mappedValue).map(Number)
);