Skip to content

Commit

Permalink
add metadata to features
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Jul 1, 2021
1 parent f80aa2a commit 35a5b60
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion x-pack/plugins/maps/server/mvt/get_tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ export async function getTile({
)
.toPromise();

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

const counts = countVectorShapeTypes(features);

const fieldNames = new Set<string>();
features.forEach((feature) => {
for (const key in feature.properties) {
if (feature.properties.hasOwnProperty(key) && key !== 'key' && key !== 'gridCentroid') {
fieldNames.add(key);
}
}
});

const fieldMeta: FieldMeta = {};
fieldNames.forEach((fieldName: string) => {
const rangeMeta = pluckRangeFieldMeta(features, fieldName, (rawValue: unknown) => {
return typeof rawValue === 'number' ? rawValue : NaN;
});
const categoryMeta = pluckCategoryFieldMeta(features, fieldName, 20);

if (!fieldMeta[fieldName]) {
fieldMeta[fieldName] = {};
}

if (rangeMeta) {
fieldMeta[fieldName].range = rangeMeta;
}

if (categoryMeta) {
fieldMeta[fieldName].categories = categoryMeta;
}
});

const metadataFeature: TileMetaFeature = {
type: 'Feature',
properties: {
[KBN_METADATA_FEATURE]: true,
[KBN_IS_TILE_COMPLETE]: true,
[KBN_VECTOR_SHAPE_TYPE_COUNTS]: counts,
[KBN_FEATURE_COUNT]: features.length,
fieldMeta,
},
geometry: esBboxToGeoJsonPolygon(tileToESBbox(x, y, z), tileToESBbox(x, y, z)),
};
Expand Down

0 comments on commit 35a5b60

Please sign in to comment.