Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Fix] Dispatch click event instead of click() (#2345)

Igor Dykhta6ef400d2ce02
diff --git a/src/utils/src/export-utils.ts b/src/utils/src/export-utils.ts
index aa840b932..69e2ab9b4 100644
--- a/src/utils/src/export-utils.ts
+++ b/src/utils/src/export-utils.ts
@@ -138,7 +138,15 @@ export function downloadFile(fileBlob: Blob, fileName: string) {
link.setAttribute('download', fileName);
document.body.appendChild(link);
- link.click();
+ // in some cases where maps are embedded, e.g. need to
+ // create and dispatch an event so that the browser downloads
+ // the file instead of navigating to the url
+ const evt = new MouseEvent('click', {
+ view: window,
+ bubbles: false,
+ cancelable: true
+ });
+ link.dispatchEvent(evt);
document.body.removeChild(link);
URL.revokeObjectURL(url);
}