diff --git a/src/ui/public/vis_maps/__tests__/geohash_layer.js b/src/ui/public/vis_maps/__tests__/geohash_layer.js index 846f195eb4033..c61ed5d991bf8 100644 --- a/src/ui/public/vis_maps/__tests__/geohash_layer.js +++ b/src/ui/public/vis_maps/__tests__/geohash_layer.js @@ -483,6 +483,20 @@ describe('kibana_map tests', function () { }); + it('should not throw when fitting on empty-data layer', function () { + + const geohashLayer = new GeohashLayer({ + type: 'FeatureCollection', + features: [] + }, { 'mapType': 'Scaled Circle Markers' }, kibanaMap.getZoomLevel(), kibanaMap); + kibanaMap.addLayer(geohashLayer); + + expect(() => { + kibanaMap.fitToData(); + }).to.not.throwException(); + }); + + }); }); diff --git a/src/ui/public/vis_maps/kibana_map.js b/src/ui/public/vis_maps/kibana_map.js index 946bf50d308e9..0d8dec910fb11 100644 --- a/src/ui/public/vis_maps/kibana_map.js +++ b/src/ui/public/vis_maps/kibana_map.js @@ -474,7 +474,7 @@ export class KibanaMap extends EventEmitter { } }); - if (bounds) { + if (bounds && bounds.isValid()) { this._leafletMap.fitBounds(bounds); } }