diff --git a/x-pack/plugins/maps/public/actions/map_actions.js b/x-pack/plugins/maps/public/actions/map_actions.js index ea2602397702b..5aa7c74a7b30b 100644 --- a/x-pack/plugins/maps/public/actions/map_actions.js +++ b/x-pack/plugins/maps/public/actions/map_actions.js @@ -587,8 +587,8 @@ export function fitToDataBounds() { const b = bounds[i]; //filter out undefined bounds (uses Infinity due to turf responses) - if ( + b === null || b.minLon === Infinity || b.maxLon === Infinity || b.minLat === -Infinity || diff --git a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.js b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.js index b3341a1061d68..0302531117a6f 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.js +++ b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.js @@ -161,18 +161,13 @@ export class AbstractESSource extends AbstractVectorSource { let esBounds; try { const esResp = await searchSource.fetch(); - esBounds = _.get(esResp, 'aggregations.fitToBounds.bounds'); + if (!esResp.aggregations.fitToBounds.bounds) { + // aggregations.fitToBounds is empty object when there are no matching documents + return null; + } + esBounds = esResp.aggregations.fitToBounds.bounds; } catch (error) { - esBounds = { - top_left: { - lat: 90, - lon: -180, - }, - bottom_right: { - lat: -90, - lon: 180, - }, - }; + return null; } const minLon = esBounds.top_left.lon;