@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.25 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import t from"../../../core/Error.js";import{renderingSanitizer as e}from"../../../core/sanitizerUtils.js";import{blobUrlToBlob as r,downloadBlobAsFile as o}from"../../../core/urlUtils.js";import{convertFeaturesToCSV as i}from"../../../exports/csv.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),m=await i(p,{includeGeometry:!a.isTable&&(n||"point"===p.geometryType),outFields:u});if(!m)throw new t("export-csv:no-output","Unable to generate a valid export string");const d=new Blob([m],{type:"text/csv"}),f=e.sanitize(a.title);if(s())try{const t=await showSaveFilePicker({suggestedName:f,types:[{accept:{"text/csv":[".csv"]}}]}),e=await t.createWritable();await e.write(d),await e.close()}catch(y){if(y instanceof t&&"AbortError"!==y.name)throw y}else o(d,`${f}.csv`)}async function n(t){if(!t?.url)return;const e=await r(`${t.url}`);o(e,t.name)}export{n as downloadAttachmentInfo,a as exportToCSV,s as supportsFileSystemAccess};