Skip to content

Commit a4fa89d

Browse files
committed
[Maps] handle case where fit to bounds does not match any documents (#66307)
* [Maps] handle case where fit to bounds does not match any documents * review feedback
1 parent f830ec2 commit a4fa89d

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

x-pack/plugins/maps/public/actions/map_actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ export function fitToDataBounds() {
587587
const b = bounds[i];
588588

589589
//filter out undefined bounds (uses Infinity due to turf responses)
590-
591590
if (
591+
b === null ||
592592
b.minLon === Infinity ||
593593
b.maxLon === Infinity ||
594594
b.minLat === -Infinity ||

x-pack/plugins/maps/public/classes/sources/es_source/es_source.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,13 @@ export class AbstractESSource extends AbstractVectorSource {
161161
let esBounds;
162162
try {
163163
const esResp = await searchSource.fetch();
164-
esBounds = _.get(esResp, 'aggregations.fitToBounds.bounds');
164+
if (!esResp.aggregations.fitToBounds.bounds) {
165+
// aggregations.fitToBounds is empty object when there are no matching documents
166+
return null;
167+
}
168+
esBounds = esResp.aggregations.fitToBounds.bounds;
165169
} catch (error) {
166-
esBounds = {
167-
top_left: {
168-
lat: 90,
169-
lon: -180,
170-
},
171-
bottom_right: {
172-
lat: -90,
173-
lon: 180,
174-
},
175-
};
170+
return null;
176171
}
177172

178173
const minLon = esBounds.top_left.lon;

0 commit comments

Comments
 (0)