[Maps] Add support for envelope (#80614)

This commit is contained in:
Thomas Neirynck 2020-10-15 13:58:54 -04:00 committed by GitHub
parent 6b8e8a5b46
commit b1af4ba9ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View file

@ -175,6 +175,16 @@ export function convertESShapeToGeojsonGeometry(value) {
geoJson.type = GEO_JSON_TYPE.GEOMETRY_COLLECTION;
break;
case 'envelope':
// format defined here https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#_envelope
const polygon = formatEnvelopeAsPolygon({
minLon: geoJson.coordinates[0][0],
maxLon: geoJson.coordinates[1][0],
minLat: geoJson.coordinates[1][1],
maxLat: geoJson.coordinates[0][1],
});
geoJson.type = polygon.type;
geoJson.coordinates = polygon.coordinates;
break;
case 'circle':
const errorMessage = i18n.translate(
'xpack.maps.es_geo_utils.convert.unsupportedGeometryTypeErrorMessage',

View file

@ -250,6 +250,30 @@ describe('geoShapeToGeometry', () => {
expect(shapes[0].coordinates).toEqual(coordinates);
});
it('Should convert envelope to geojson', () => {
const coordinates = [
[100.0, 1.0],
[101.0, 0.0],
];
const value = {
type: 'envelope',
coordinates: coordinates,
};
const shapes = [];
geoShapeToGeometry(value, shapes);
expect(shapes.length).toBe(1);
expect(shapes[0].type).toBe('Polygon');
expect(shapes[0].coordinates).toEqual([
[
[100, 1],
[100, 0],
[101, 0],
[101, 1],
[100, 1],
],
]);
});
it('Should convert array of values', () => {
const linestringCoordinates = [
[-77.03653, 38.897676],