Skip to content

Commit

Permalink
[Maps] Add support for envelope (#80614)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Oct 15, 2020
1 parent 6b8e8a5 commit b1af4ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit b1af4ba

Please sign in to comment.