-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reuse utility re-enable dynamic styling update tile ts fixes
- Loading branch information
1 parent
6e2455f
commit 38e3a54
Showing
6 changed files
with
104 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// This implementation: | ||
// - does not include meta-fields | ||
// - does not validate the schema against the index-pattern (e.g. nested fields) | ||
// In the context of .mvt this is sufficient: | ||
// - only fields from the response are packed in the tile (more efficient) | ||
// - query-dsl submitted from the client, which was generated by the IndexPattern | ||
// todo: Ideally, this should adapt/reuse from https://github.com/elastic/kibana/blob/52b42a81faa9dd5c102b9fbb9a645748c3623121/src/plugins/data/common/index_patterns/index_patterns/flatten_hit.ts#L26 | ||
import { GeoJsonProperties } from 'geojson'; | ||
|
||
export function flattenHit(geometryField: string, hit: GeoJsonProperties): GeoJsonProperties { | ||
const flat: GeoJsonProperties = {}; | ||
if (hit) { | ||
flattenSource(flat, '', hit._source, geometryField); | ||
if (hit.fields) { | ||
flattenFields(flat, hit.fields); | ||
} | ||
|
||
// Attach meta fields | ||
flat._index = hit._index; | ||
flat._id = hit._id; | ||
} | ||
return flat; | ||
} | ||
|
||
function flattenSource( | ||
accum: GeoJsonProperties, | ||
path: string, | ||
properties: GeoJsonProperties = {}, | ||
geometryField: string | ||
): GeoJsonProperties { | ||
accum = accum || {}; | ||
for (const key in properties) { | ||
if (properties.hasOwnProperty(key)) { | ||
const newKey = path ? path + '.' + key : key; | ||
let value; | ||
if (geometryField === newKey) { | ||
value = properties[key]; // do not deep-copy the geometry | ||
} else if (properties[key] !== null && typeof value === 'object' && !Array.isArray(value)) { | ||
value = flattenSource(accum, newKey, properties[key], geometryField); | ||
} else { | ||
value = properties[key]; | ||
} | ||
accum[newKey] = value; | ||
} | ||
} | ||
return accum; | ||
} | ||
|
||
function flattenFields(accum: GeoJsonProperties = {}, fields: GeoJsonProperties[]) { | ||
accum = accum || {}; | ||
for (const key in fields) { | ||
if (fields.hasOwnProperty(key)) { | ||
const value = fields[key]; | ||
if (Array.isArray(value)) { | ||
accum[key] = value[0]; | ||
} else { | ||
accum[key] = value; | ||
} | ||
} | ||
} | ||
} |