Skip to content

Commit 35a5b60

Browse files
add metadata to features
1 parent f80aa2a commit 35a5b60

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

x-pack/plugins/maps/server/mvt/get_tile.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ export async function getTile({
307307
)
308308
.toPromise();
309309

310-
// Todo: pass in epochMillies-fields
311310
const featureCollection = hitsToGeoJson(
312311
// @ts-expect-error hitsToGeoJson should be refactored to accept estypes.SearchHit
313312
documentsResponse.rawResponse.hits.hits,
@@ -330,13 +329,44 @@ export async function getTile({
330329
}
331330

332331
const counts = countVectorShapeTypes(features);
332+
333+
const fieldNames = new Set<string>();
334+
features.forEach((feature) => {
335+
for (const key in feature.properties) {
336+
if (feature.properties.hasOwnProperty(key) && key !== 'key' && key !== 'gridCentroid') {
337+
fieldNames.add(key);
338+
}
339+
}
340+
});
341+
342+
const fieldMeta: FieldMeta = {};
343+
fieldNames.forEach((fieldName: string) => {
344+
const rangeMeta = pluckRangeFieldMeta(features, fieldName, (rawValue: unknown) => {
345+
return typeof rawValue === 'number' ? rawValue : NaN;
346+
});
347+
const categoryMeta = pluckCategoryFieldMeta(features, fieldName, 20);
348+
349+
if (!fieldMeta[fieldName]) {
350+
fieldMeta[fieldName] = {};
351+
}
352+
353+
if (rangeMeta) {
354+
fieldMeta[fieldName].range = rangeMeta;
355+
}
356+
357+
if (categoryMeta) {
358+
fieldMeta[fieldName].categories = categoryMeta;
359+
}
360+
});
361+
333362
const metadataFeature: TileMetaFeature = {
334363
type: 'Feature',
335364
properties: {
336365
[KBN_METADATA_FEATURE]: true,
337366
[KBN_IS_TILE_COMPLETE]: true,
338367
[KBN_VECTOR_SHAPE_TYPE_COUNTS]: counts,
339368
[KBN_FEATURE_COUNT]: features.length,
369+
fieldMeta,
340370
},
341371
geometry: esBboxToGeoJsonPolygon(tileToESBbox(x, y, z), tileToESBbox(x, y, z)),
342372
};

0 commit comments

Comments
 (0)