Show toast error when geojson/topojson file cannot be downloaded (#17502)
This commit is contained in:
parent
fd37e90777
commit
82ac7762a6
|
@ -5,7 +5,7 @@ import d3 from 'd3';
|
|||
import { KibanaMapLayer } from '../../tile_map/public/kibana_map_layer';
|
||||
import { truncatedColorMaps } from 'ui/vislib/components/color/truncated_colormaps';
|
||||
import * as topojson from 'topojson-client';
|
||||
|
||||
import { toastNotifications } from 'ui/notify';
|
||||
|
||||
const EMPTY_STYLE = {
|
||||
weight: 1,
|
||||
|
@ -61,6 +61,7 @@ export default class ChoroplethLayer extends KibanaMapLayer {
|
|||
|
||||
this._showAllShapes = showAllShapes;
|
||||
this._geojsonUrl = geojsonUrl;
|
||||
|
||||
this._leafletLayer = L.geoJson(null, {
|
||||
onEachFeature: (feature, layer) => {
|
||||
layer.on('click', () => {
|
||||
|
@ -119,6 +120,21 @@ export default class ChoroplethLayer extends KibanaMapLayer {
|
|||
} catch (e) {
|
||||
this._loaded = true;
|
||||
this._error = true;
|
||||
|
||||
let errorMessage;
|
||||
if (e.status === 404) {
|
||||
errorMessage = `Server responding with '404' when attempting to fetch ${geojsonUrl}.
|
||||
Make sure the file exists at that location.`;
|
||||
} else {
|
||||
errorMessage = `Cannot download ${geojsonUrl} file. Please ensure the
|
||||
CORS configuration of the server permits requests from the Kibana application on this host.`;
|
||||
}
|
||||
|
||||
toastNotifications.addDanger({
|
||||
title: 'Error downloading vector data',
|
||||
text: errorMessage,
|
||||
});
|
||||
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue