UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.32 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import t from"../../../core/Error.js";import{downloadBlobAsFile as e,blobUrlToBlob as r}from"../../../core/urlUtils.js";import{convertFeaturesToCSV as o}from"../../../exports/csv.js";import{renderingSanitizer as i}from"../../support/widgetUtils.js";function s(){return"showSaveFilePicker"in window&&(()=>{try{return window.self===window.top}catch{return!1}})()}async function a(r){const{layer:a,includeGeometry:n,objectIds:c,outFields:l}=r,u=l??a.outFields??["*"],w=a.createQuery();w.objectIds=c,w.outFields=u;const p=await a.queryFeatures(w),d=await o(p,{includeGeometry:!a.isTable&&(n||"point"===p.geometryType),outFields:u});if(!d)throw new t("export-csv:no-output","Unable to generate a valid export string");const m=new Blob([d],{type:"text/csv"}),f=i.sanitize(a.title);if(s())try{const t=await showSaveFilePicker({suggestedName:f,types:[{accept:{"text/csv":[".csv"]}}]}),e=await t.createWritable();await e.write(m),await e.close()}catch(y){if(y instanceof t&&"AbortError"!==y.name)throw y}else e(m,`${f}.csv`)}async function n(t){if(!t?.url)return;const o=await r(`${t.url}`);e(o,t.name)}export{n as downloadAttachmentInfo,a as exportToCSV,s as supportsFileSystemAccess};