@vertigis/arcgis-extensions 53.10.0 → 53.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/data/convert.d.ts +22 -0
  2. package/data/convert.js +1 -1
  3. package/data/support/_lpkxConverter.d.ts +12 -0
  4. package/data/support/_lpkxConverter.js +1 -0
  5. package/data/support/lpkxInterfaces.d.ts +359 -0
  6. package/data/support/lpkxInterfaces.js +1 -0
  7. package/docs/html/assets/navigation.js +1 -1
  8. package/docs/html/assets/search.js +1 -1
  9. package/docs/html/functions/data_convert.lpkxToLayerExtensions.html +5 -0
  10. package/docs/html/functions/data_support__lpkxConverter.createLpkxLayer.html +7 -0
  11. package/docs/html/interfaces/data_convert.LpkxToLayerExtensionsOptions.html +6 -0
  12. package/docs/html/interfaces/data_support_lpkxInterfaces.CIMFillLike.html +4 -0
  13. package/docs/html/interfaces/data_support_lpkxInterfaces.ColorObject.html +6 -0
  14. package/docs/html/interfaces/data_support_lpkxInterfaces.GPValue.html +4 -0
  15. package/docs/html/interfaces/data_support_lpkxInterfaces.GeoProcessedLpkxData.html +12 -0
  16. package/docs/html/interfaces/data_support_lpkxInterfaces.LpkxCimColorObject.html +4 -0
  17. package/docs/html/interfaces/data_support_lpkxInterfaces.LpkxCimLabelClass.html +12 -0
  18. package/docs/html/interfaces/data_support_lpkxInterfaces.LpkxCimRenderer.html +10 -0
  19. package/docs/html/interfaces/data_support_lpkxInterfaces.LpkxCimRendererClass.html +8 -0
  20. package/docs/html/interfaces/data_support_lpkxInterfaces.LpkxCimRendererGroup.html +4 -0
  21. package/docs/html/interfaces/data_support_lpkxInterfaces.LpkxCimSymbolReference.html +4 -0
  22. package/docs/html/interfaces/data_support_lpkxInterfaces.LyrxLayerDefinition.html +12 -0
  23. package/docs/html/interfaces/data_support_lpkxInterfaces.LyrxResult.html +4 -0
  24. package/docs/html/modules/data_convert.html +2 -0
  25. package/docs/html/modules/data_support__lpkxConverter.html +2 -0
  26. package/docs/html/modules/data_support_lpkxInterfaces.html +37 -0
  27. package/docs/html/modules.html +2 -0
  28. package/docs/html/types/data_support_lpkxInterfaces.CIMLineSymbolLike.html +2 -0
  29. package/docs/html/types/data_support_lpkxInterfaces.CIMPointSymbolLike.html +2 -0
  30. package/docs/html/types/data_support_lpkxInterfaces.CIMPolygonSymbolLike.html +2 -0
  31. package/docs/html/types/data_support_lpkxInterfaces.CIMSolidFillLike.html +2 -0
  32. package/docs/html/types/data_support_lpkxInterfaces.CIMSolidStrokeLike.html +2 -0
  33. package/docs/html/types/data_support_lpkxInterfaces.CIMSymbolPropsWithType.html +2 -0
  34. package/docs/html/types/data_support_lpkxInterfaces.CIMTextSymbolBase.html +2 -0
  35. package/docs/html/types/data_support_lpkxInterfaces.ColorArray.html +2 -0
  36. package/docs/html/types/data_support_lpkxInterfaces.ColorInput.html +2 -0
  37. package/docs/html/types/data_support_lpkxInterfaces.ColorValues.html +2 -0
  38. package/docs/html/types/data_support_lpkxInterfaces.EsriSupportedSymbol.html +2 -0
  39. package/docs/html/types/data_support_lpkxInterfaces.EsriSupportedSymbolProps.html +2 -0
  40. package/docs/html/types/data_support_lpkxInterfaces.LpkxCimColor.html +2 -0
  41. package/docs/html/types/data_support_lpkxInterfaces.LpkxCimColorValues.html +2 -0
  42. package/docs/html/types/data_support_lpkxInterfaces.LpkxCimPolygonSymbol.html +3 -0
  43. package/docs/html/types/data_support_lpkxInterfaces.LpkxCimSolidFill.html +2 -0
  44. package/docs/html/types/data_support_lpkxInterfaces.LpkxCimSolidStroke.html +2 -0
  45. package/docs/html/types/data_support_lpkxInterfaces.LpkxCimSymbol.html +2 -0
  46. package/docs/html/types/data_support_lpkxInterfaces.LpkxCimTextSymbol.html +9 -0
  47. package/docs/html/types/data_support_lpkxInterfaces.PictureMarkerSymbolPropsWithType.html +2 -0
  48. package/docs/html/types/data_support_lpkxInterfaces.SimpleFillSymbolPropsWithType.html +2 -0
  49. package/docs/html/types/data_support_lpkxInterfaces.SimpleLineSymbolPropsWithType.html +2 -0
  50. package/docs/html/types/data_support_lpkxInterfaces.SimpleMarkerSymbolPropsWithType.html +2 -0
  51. package/docs/html/types/data_support_lpkxInterfaces.TextSymbolPropsWithType.html +2 -0
  52. package/docs/html/variables/version.version.html +1 -1
  53. package/package.json +1 -1
  54. package/version.d.ts +1 -1
  55. package/version.js +1 -1
package/data/convert.d.ts CHANGED
@@ -11,6 +11,7 @@ import { DateFormat, NumberFormat, TimeFormat } from "../utilities/format/format
11
11
  import { FeatureSet } from "./FeatureSet.js";
12
12
  import type { IDxfJsonComponentContext } from "./support/_dxfInterfaces.js";
13
13
  import { type GeoProcessedFgdbData } from "./support/fgdbConverter.js";
14
+ import type { GeoProcessedLpkxData } from "./support/lpkxInterfaces.js";
14
15
  /**
15
16
  * A union of simple fill, line, and marker symbols.
16
17
  */
@@ -317,6 +318,19 @@ export interface DxfToLayerExtensionsOptions {
317
318
  */
318
319
  outputSpatialReference: SpatialReference;
319
320
  }
321
+ /**
322
+ * Options for converting a LPKX file to layer extensions.
323
+ */
324
+ export interface LpkxToLayerExtensionsOptions {
325
+ /**
326
+ * The URL of the display service to use for the dynamic layer.
327
+ */
328
+ displayServiceUrl: string;
329
+ /**
330
+ * The geoprocessing result data for the LPKX file.
331
+ */
332
+ geoProcessedLpkxData: GeoProcessedLpkxData;
333
+ }
320
334
  /**
321
335
  * Options for converting a FGDB file to layer extensions.
322
336
  */
@@ -425,6 +439,14 @@ export declare function toShapefile(featureSet: FeatureSet, options?: ToShapefil
425
439
  * extensions.
426
440
  */
427
441
  export declare function kmlToLayerExtensions(kmlBlob: Blob): Promise<LayerExtension[]>;
442
+ /**
443
+ * Converts a Blob that represents LPKX data to an array of layer extensions.
444
+ *
445
+ * @param lpkxBlob The Blob containing LPKX data to convert.
446
+ * @param options The options for converting the LPKX file.
447
+ * @returns A promise that resolves to an array of `LayerExtension` objects.
448
+ */
449
+ export declare function lpkxToLayerExtensions(lpkxBlob: Blob, options: LpkxToLayerExtensionsOptions): Promise<LayerExtension[]>;
428
450
  /**
429
451
  * Converts a Blob that represents DXF data to an array of layer extensions.
430
452
  *
package/data/convert.js CHANGED
@@ -1 +1 @@
1
- import e from"@arcgis/core/Color.js";import t from"@arcgis/core/Graphic.js";import r from"@arcgis/core/geometry/Point";import o from"@arcgis/core/geometry/Polygon.js";import n from"@arcgis/core/geometry/Polyline.js";import a from"@arcgis/core/geometry/SpatialReference";import i from"@arcgis/core/layers/FeatureLayer.js";import s from"@arcgis/core/layers/GroupLayer.js";import c from"@arcgis/core/layers/support/Field.js";import l from"@arcgis/core/renderers/SimpleRenderer.js";import m from"@arcgis/core/renderers/UniqueValueRenderer.js";import u from"@arcgis/core/renderers/support/UniqueValueInfo.js";import f from"@arcgis/core/symbols/MeshSymbol3D.js";import y from"@arcgis/core/symbols/PictureMarkerSymbol.js";import p from"@arcgis/core/symbols/SimpleFillSymbol.js";import d from"@arcgis/core/symbols/SimpleLineSymbol.js";import g from"@arcgis/core/symbols/SimpleMarkerSymbol.js";import w from"dxf-parser";import{geometryTypeToJson as h}from"../json/GeometryJson.js";import{translate as F}from"../locale/language.js";import{INVARIANT as S}from"../locale.js";import{FeatureCollectionLayerExtension as T}from"../mapping/FeatureCollectionLayerExtension.js";import{GroupLayerExtension as N}from"../mapping/GroupLayerExtension.js";import{MapImageLayerExtension as O}from"../mapping/MapImageLayerExtension.js";import{CaseInsensitiveObservableMap as b}from"../utilities/CaseInsensitiveObservableMap.js";import{Time as D}from"../utilities/Time.js";import{checkArg as M,assertNever as x}from"../utilities/checkArg.js";import{isPoint as E,isMultipoint as R,isPolyline as A,isPolygon as I,isExtent as G}from"../utilities/esri.js";import{parse as _,format as L,DEFAULT_PARSING_FORMATS as C,INVALID_DATE as v}from"../utilities/format/date.js";import{DateFormat as P,NumberFormat as j,TimeFormat as U}from"../utilities/format/formats.js";import{parse as $,format as H}from"../utilities/format/number.js";import{parse as B,format as J,DEFAULT_PARSING_FORMATS as z}from"../utilities/format/time.js";import{project as k,esriToWKT as W,wktToEsri as X,esriWkidToWkt as q,esriWktToWkid as Y,esriToGeoJSON as Z,geoJSONToEsri as K}from"../utilities/geometry.js";import{getLogger as V}from"../utilities/log.js";import{isNumeric as Q}from"../utilities/number.js";import{delay as ee}from"../utilities/promise.js";import{caseInsensitiveEquals as te}from"../utilities/string.js";import{Feature as re}from"./Feature.js";import{FeatureSet as oe}from"./FeatureSet.js";import{DxfEntityProcessor as ne}from"./support/_dxfConverters.js";import{createFgdbLayer as ae}from"./support/fgdbConverter.js";const ie=["=","-","+","@"],se='"',ce="\r\n",le="\n",me=[...C.map(Je),"M/d/yy"],ue=[...z.map(ke).map((e=>e.replace("AM/PM","tt")))],fe=/(\w+)_(point|multipoint|polyline|polygon)z?/;var ye;function pe(){return V("geocortex.api.data.convert")}!function(e){e.DATE="D",e.NUMBER="N",e.STRING="C",e.BOOLEAN="L"}(ye||(ye={}));export const FIELD_NAME_REGEX=/[^a-zA-Z\d_]/g;export var GeometryFormat;!function(e){e.NONE="NONE",e.WKT="WKT",e.XY="XY",e.XYZ="XYZ",e.LAT_LON="LAT_LONG",e.GEO_JSON="GEO_JSON",e.ARCGIS_JSON="ARCGIS_JSON"}(GeometryFormat||(GeometryFormat={}));export const geometryTypeHeaders={[GeometryFormat.XYZ]:[["x","y","z"]],[GeometryFormat.XY]:[["x","y"]],[GeometryFormat.LAT_LON]:[["latitude","longitude"],["lat","lon"],["lat","long"]],[GeometryFormat.ARCGIS_JSON]:[["geometry"]],[GeometryFormat.GEO_JSON]:[["geometry"]],[GeometryFormat.WKT]:[["geometry"]]};const de=[[GeometryFormat.ARCGIS_JSON,_e],[GeometryFormat.GEO_JSON,Le],[GeometryFormat.WKT,Ce]],ge=new Map(de);export async function uploadDataToFeatureSet(e){const t=await async function(e){const{data:t,includeHeaderRow:o,geometryFormat:n,geometryFields:a,locale:i,numberFormat:s,inSpatialReference:c}=e,l=o?t.slice(1):t;if(n===GeometryFormat.NONE)return{columnIndices:[]};const m=e=>je(e,i,s),u=(e,t)=>{const o=t===GeometryFormat.XYZ,n=t===GeometryFormat.LAT_LON;return{columnIndices:e,geometries:l.map((t=>{if(t.length>=Math.max(...e)&&Q(t[e[0]]?.raw,i)&&Q(t[e[1]]?.raw,i)&&(!o||Q(t[e[2]]?.raw,i)))return new r({x:m(n?t[e[1]].raw:t[e[0]].raw),y:m(n?t[e[0]].raw:t[e[1]].raw),z:o?m(t[e[2]].raw):0,spatialReference:c})}))}},f=async(e,t)=>({columnIndices:[e],geometries:await Promise.all(l.map((t=>t[e])).map((e=>{if(e?.raw)return t(e.raw.toString(),c)})))}),y=async(e,t)=>{switch(t){case GeometryFormat.NONE:return{columnIndices:[0]};case GeometryFormat.LAT_LON:case GeometryFormat.XYZ:case GeometryFormat.XY:return u(e,t);case GeometryFormat.ARCGIS_JSON:return f(e[0],_e);case GeometryFormat.GEO_JSON:return f(e[0],Le);case GeometryFormat.WKT:return f(e[0],Ce);default:return x(t,new Error(`Unknown geometry format "${t}".`))}};if(n){const e=ve(o?t[0]:t[0].map(((e,t)=>({raw:t.toString()}))),n,o?a:a.map((e=>""+(parseInt(e.match(/\d+/g)[0])-1))));if(o&&void 0===e)throw new Error(`Error parsing file data: Expected geometry columns ${geometryTypeHeaders[n][0].join(",")} are missing for GeometryType.${n}`);return y(e??[0],n)}const[p,d]=await Ue(t,c,o);if(p===GeometryFormat.NONE)return{columnIndices:[]};return d.length>1?u(d,p):f(d[0],ge.get(p))}(e),o=function(e,t){const{data:r,displayField:o,includeHeaderRow:n,inSpatialReference:a,outSpatialReference:i,generatePrimaryKey:s}=e,c={fields:[]},l=e=>!(!t.columnIndices||0===t.columnIndices.length)&&t.columnIndices.includes(e);let{primaryKeyField:m}=e,u=0;for(let t=0;t<r[0].length;t++){if(l(t))continue;const o=He(e,t,!s&&!m&&!c.fields.find((e=>"esriFieldTypeOID"===e.type)));let a=r[0][t]?.raw?.toString(),i=a?.replace(FIELD_NAME_REGEX,"_");n&&i||(i="field"+ ++u,a=F("gcx.api.data.convert.import-field-alias",u)),c.fields.push({alias:a,name:i,type:o}),"esriFieldTypeOID"===o&&(m=i)}if(c.spatialReference=i??t.geometries?.[0]?.spatialReference??a,t.geometries?.length){const e=t.geometries.filter((e=>void 0!==e)).map((e=>e.type)),r=e[0];c.geometryType=e.every((e=>e===r))?h(r):void 0}if(!c.fields.find((e=>"esriFieldTypeOID"===e.type))){const e=c.fields.length+1,t=!!c.fields.find((e=>"objectid"===e.name.toLowerCase()));m=t?`OBJECTID_${e}`:"OBJECTID",c.fields.push({name:m,alias:m,type:"esriFieldTypeOID"})}return c.displayField=o??c.fields.find((e=>!te(e.name,m)&&"esriFieldTypeString"===e.type))?.name??c.fields.find((e=>!te(e.name,m)))?.name??m,c.primaryKeyField=m,c}(e,t),n=await async function(e,t,r){const{data:o,includeHeaderRow:n,outFields:a,escapeFormulaChars:i,locale:s,numberFormat:c,dateFormat:l,timeFormat:m}=e,{spatialReference:u}=r,f=[],y=n?o.slice(1):o,p=(e,r)=>!t.columnIndices||0===t.columnIndices.length||!t.columnIndices.includes(r);return await Promise.all(y.map((async(e,o)=>{const n=new re;for(let t=0;t<r.fields.length;t++){const u=r.fields[t],f=e.filter(p);if(a.includes("*")||a.filter((e=>te(e,u.name))).length>0){let e=await Be(f[t]?.raw,u,{escapeFormulaChars:i,dateFormat:l,numberFormat:c,timeFormat:m,locale:s});"esriFieldTypeOID"===u.type&&null===e&&(e=o),n.attributes.set(u.name,e)}}t.geometries&&(n.geometry=await De(t.geometries[o],u)),f.push(n)}))),f}(e,t,o);return new oe({features:n,schema:o})}export async function toCsv(e,t){M("featureSet",e).isNotMissing();const r=Array.from(e),o={...{useFormattedValues:!1,alwaysQuote:!1,escapeFormulaChars:!0,delimiter:",",dateFormat:P.ROUND_TRIP,timeFormat:U.ROUND_TRIP,geometryFormat:r.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,includeByteOrderMark:!0,outSpatialReference:a.WGS84,includeHeaderRow:!0,outFields:Oe(e.source),rowDelimiter:navigator.platform?.startsWith("Win")?ce:"\n"},...t},{includeByteOrderMark:n,includeHeaderRow:i,delimiter:s,outFields:c,rowDelimiter:l}=o,m=[];n&&m.push("\ufeff");const u=Te(r,o),f=Ne(r,c,e.schema,!0),y=Ne(r,c,e.schema,!1);if(i){const e=[];for(const t of u)e.push(Me(t,o));for(const t of f)e.push(Me(t,o));for(const t of y)e.push(Me(t,o));const t=e.join(s)+l;m.push(t)}await Promise.all(r.map((async e=>{const t=[],r=(t,r)=>{const o=Ee(e,t,r),n=e.schema.findFieldByName(t)?.type;return Me(xe(o,{...r,isDateOnly:"date-only"===n}),r)};t.push(...await async function(e,t){let r=await be(e,t);t.geometryFormat!==GeometryFormat.XYZ&&t.geometryFormat!==GeometryFormat.XY&&t.geometryFormat!==GeometryFormat.LAT_LON||(r=r.map((e=>void 0===e?"":xe(e,t))));return r.map((e=>""===e?"":Me(e,t)))}(e.geometry,o)),t.push(...f.map((e=>r(e,o)))),t.push(...y.map((e=>r(e,o))));const n=`${t.join(s)}${l}`;m.push(n)})));return new Blob(m,{type:"text/plain",endings:"\n"===l||l===ce?"transparent":"native"})}export async function csvToUploadData(e,t){let r;if(M("csvData",e).isNotMissing(),e instanceof Blob){const t=new Promise(((t,r)=>{const o=new FileReader;o.onload=()=>{t(o.result)},o.onerror=()=>{r(o.error)},o.readAsText(e)}));r=await t}else r=e;const o=he(t),n=o.rowDelimiter||function(e){let t=le;return Ge(e,ce,((r,o)=>(0===r&&o===e.length||(t=ce),!1))),t}(r),a=o.delimiter??function(e,t,r){const o=",";if(0===e.length)return o;const n=[];if(Ge(e,t,((t,r)=>(r!==e.length||t!==r)&&(n.push(e.substring(t,r)),n.length<3))),0===n.length)return o;let a=[{delimiter:",",rowsDelimiterOccurrences:[],rowsNumberAdjacentOccurrences:[]},{delimiter:";",rowsDelimiterOccurrences:[]},{delimiter:"|",rowsDelimiterOccurrences:[]},{delimiter:"\t",rowsDelimiterOccurrences:[]},{delimiter:" ",rowsDelimiterOccurrences:[]}].filter((e=>n[0].includes(e.delimiter)));if(0===a.length)return o;for(const e of n)for(const t of a){let o=0,n=0;Ge(e,t.delimiter,((a,i)=>{if(i!==e.length&&o++,","===t.delimiter){const t=e.charAt(i-1),o=e.charAt(i+1);Q(t,r)&&Q(o,r)&&n++}return!0})),t.rowsDelimiterOccurrences.push(o),","===t.delimiter&&t.rowsNumberAdjacentOccurrences.push(n)}if(a=a.filter((e=>e.rowsDelimiterOccurrences.every((t=>e.rowsDelimiterOccurrences[0]===t)))).sort(((e,t)=>t.rowsDelimiterOccurrences[0]-e.rowsDelimiterOccurrences[0])),a.length>1&&","===a[0].delimiter&&null!=r&&r!==S){const e=a[0];if(null!=e&&","===e.delimiter&&","===Intl.NumberFormat(r).formatToParts(1.1).find((e=>"decimal"===e.type))?.value)for(let t=0;t<e.rowsDelimiterOccurrences.length;t++)if(e.rowsDelimiterOccurrences[t]<=e.rowsNumberAdjacentOccurrences[t]){a=a.filter((e=>","!==e.delimiter));break}}if(0===a.length)return o;return a[0].delimiter}(r,n,t.locale),i=function(e,t,r){const o=[],n=(e,t)=>{const o=[];return Ge(e,r,((r,n)=>{const a=e.substring(r,n);return o.push({raw:Ie(a,t,o.length)}),!0})),o};if(Ge(e,t,((t,r)=>{const a=e.substring(t,r);return a.length>0&&o.push(n(a,o.length)),!0})),o.length){const e=o[0].length;o.forEach(((t,r)=>{if(t.length!==e)throw new Error(`Detected invalid CSV: Row ${r} does not have expected number of columns: ${e}`)}))}return o}(r,n,a);let{geometryFormat:s,geometryFields:c}=t;if(!s){const[e,t]=await Ue(i,o.inSpatialReference,o.includeHeaderRow);s=e,c=t.map((e=>o.includeHeaderRow?i[0][e]?.raw??F("gcx.api.data.convert.import-field-alias",(e+1).toString()):F("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:i,...o,geometryFormat:s,geometryFields:c}}export async function csvToFeatureSet(e,t){const r=he(t);return uploadDataToFeatureSet(await csvToUploadData(e,r))}export async function toXLSX(e,t){M("featureSet",e).isNotMissing();const r=Array.from(e),o={...{useFormattedValues:!1,includeHeaderRow:!0,escapeFormulaChars:!0,geometryFormat:r.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,outFields:Oe(e.source),outSpatialReference:a.WGS84,dateFormat:P.DEFAULT,timeFormat:U.DEFAULT,numberFormat:j.DEFAULT,sheetName:"sheet1"},...t},{outFields:n,includeHeaderRow:i,dateFormat:s,timeFormat:c,numberFormat:l}=o,m=Te(r,o),u=Ne(r,n,e.schema,!0),f=Ne(r,n,e.schema,!1),y=await import("xlsx"),p=y.utils.sheet_new();let d=!1;if(i){const t=m.concat(u).concat(function(e,t){const r=t?.schema?.fieldExtensions.initializedItems.map((e=>e.field));return e.map((e=>r?.find((t=>te(t.name,e)))?.alias??e))}(f,e.source));d=!0,y.utils.sheet_add_aoa(p,[t],{cellDates:!0})}await Promise.all(r.map((async e=>{const t=[],r=new Set,n=new Set;t.push(...await be(e.geometry,o));for(const r of u){const n=Xe(e.attributes.get(r),o);t.push(n)}for(const a of f){const i=Ee(e,a,o);if(i instanceof D){const o=e.schema.findFieldByName(a);"time-only"===o?.type&&r.add(t.length)}else if(i instanceof Date){const r=e.schema.findFieldByName(a);"date-only"===r?.type&&n.add(t.length)}const s=Xe(i,o);t.push(s)}if(!t.every((e=>"string"!=typeof e||e.length<=32767)))return void pe().warn(`toXLSX cell limit exceeded, feature (${e.primaryKey??e.id}) omitted.`);y.utils.sheet_add_aoa(p,[t],{cellDates:!0,origin:d?-1:void 0}),d=!0;const a=y.utils.decode_range(p["!ref"]);for(let e=a.s.c;e<=a.e.c;e++){const t=p[y.utils.encode_cell({r:a.e.r,c:e})];"d"===t.t?r.has(e)?t.z=ke(c??U.ROUND_TRIP):n.has(e)?t.z=ze(s??P.ROUND_TRIP):t.z=Je(s??P.ROUND_TRIP):"n"===t.t&&(t.z=We(l))}})));const g={SheetNames:[],Sheets:{}};g.SheetNames.push(o.sheetName),g.Sheets[o.sheetName]=p;const w=y.write(g,{type:"binary",bookType:"xlsx",compression:!0,bookSST:!0,cellDates:!0}),h=new Uint8Array(w.length);for(let e=0;e<w.length;e++)h[e]=w.charCodeAt(e);return new Blob([h.buffer],{type:"text/plain"})}export async function xlsxToUploadData(e,t){M("xlsxData",e).isNotMissing();const r=Fe(t),o=await async function(e,t){const r=await import("xlsx"),o=new Promise(((o,n)=>{const a=new FileReader;a.onload=()=>{const e=new Uint8Array(a.result);let n="";for(const t of e)n+=String.fromCharCode(t);const i=r.read(n,{type:"binary",cellDates:!0}),s=t.sheetName||i.SheetNames[0],c=i.Sheets[s];o(c)},a.onerror=()=>{n(a.error)},a.readAsArrayBuffer(e)})),n=await o,a=r.utils.decode_range(n["!ref"]),i=[];for(let e=a.s.r;e<=a.e.r;e++){const t=[];for(let o=a.s.c;o<=a.e.c;o++){const a=n[`${r.utils.encode_cell({r:e,c:o})}`];a&&"d"===a.t&&a.v instanceof Date&&(a.v=new Date(a.v.getTime()+6e4*a.v.getTimezoneOffset())),t.push(a?{raw:a.v,formatted:"s"===a.t?void 0:a.w}:{raw:""})}i.push(t)}return i}(e,r);let{geometryFormat:n,geometryFields:a}=t;if(!n){const[e,t]=await Ue(o,r.inSpatialReference,r.includeHeaderRow);n=e,a=t.map((e=>r.includeHeaderRow?o[0][e]?.raw.toString()??F("gcx.api.data.convert.import-field-alias",(e+1).toString()):F("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:o,...r,geometryFormat:n,geometryFields:a}}export async function xlsxToFeatureSet(e,t){M("xlsxData",e).isNotMissing();const r=Fe(t);return uploadDataToFeatureSet(await xlsxToUploadData(e,r))}export function kmlHexToEsriColor(t){return e.fromHex(`#${t.match(/.{2}/g).reverse().join("")}`)}export function parseKMLCoordinates(e){return e.trim().split(/\s+/).map((e=>{const[t,r,o]=e.split(",").map(Number);return{x:t,y:r,z:o}}))}export function parseKMLSymbol(t,r,o){if(t){const r=t.querySelector("IconStyle > Icon > href")?.textContent;if(r)return new y({url:r,width:32,height:32});const o=t.querySelector("PolyStyle");if(o){const t=o.querySelector("color")?.textContent,r=t?kmlHexToEsriColor(t):new e([0,0,0,1]);return new p({color:r,outline:{color:[0,0,0,.5],width:1}})}const n=t.querySelector("LineStyle");if(n){const t=n.querySelector("color")?.textContent,r=t?kmlHexToEsriColor(t):new e([0,0,0,1]),o=parseFloat(n.querySelector("width")?.textContent||"1");return new d({color:r,width:o})}}return getDefaultSymbol(o,"polygon"===r?"polygon":"point"===r?"point":"polyline")}export async function toShapefile(e,t){M("featureSet",e).isNotMissing();const[{default:r},o]=await Promise.all([import("jszip"),import("../forked-libs/shp-write/index.js")]),n=Array.from(e),i={...{useFormattedValues:!1,outFields:Oe(e.source),fileName:e.title||"export"},...t},{outFields:s,outSpatialReference:c,fileName:l}=i,m=e=>e.geometry.hasZ||e.geometry.hasM,u=new Map,f=n.filter((e=>E(e.geometry)));u.set("POINTZ",f.filter(m)),u.set("POINT",f.filter((e=>!m(e))));const y=n.filter((e=>R(e.geometry)));u.set("MULTIPOINTZ",y.filter(m)),u.set("MULTIPOINT",y.filter((e=>!m(e))));const p=n.filter((e=>A(e.geometry)));u.set("POLYLINEZ",p.filter(m)),u.set("POLYLINE",p.filter((e=>!m(e))));const d=n.filter((e=>I(e.geometry)||G(e.geometry)));u.set("POLYGONZ",d.filter(m)),u.set("POLYGON",d.filter((e=>!m(e))));const g=Ne(n,s,e.schema,!0);let w=Ne(n,s,e.schema,!1);w=g.concat(w);const h=new r,F=Array.from(u.keys()).filter((e=>u.get(e).length>0));await Promise.all(F.map((async t=>{const r=u.get(t),n=await Promise.all(r.map((e=>De(e.geometry,c)))),s=await async function(e){const{wkid:t,wkt:r}=e[0].spatialReference;if(!e.every((e=>e.spatialReference.wkid===t&&e.spatialReference.wkt===r)))throw new Error("Cannot create shapefile that contains geometries with different spatial references.");return r??await q(t??a.WGS84.wkid)}(n),m=i.useFormattedValues?Object.assign({},...w.map((e=>({[e]:ye.STRING})))):function(e,t,r,o){const n={};for(const a of t){if(e.some((e=>Re(e,a)))){n[a]=ye.STRING;continue}const t=r?r.fields.find((e=>te(e.name,a))):void 0;if(t){switch(t.type){case"oid":case"double":case"integer":case"single":case"small-integer":case"big-integer":n[a]=ye.NUMBER;break;case"date":case"timestamp-offset":n[a]=o?ye.NUMBER:ye.DATE;break;default:n[a]=ye.STRING}continue}const i=(e,t)=>e.attributes.get(t)??e.presentableAttributes.get(t);e.every((e=>i(e,a)instanceof Date||void 0===i(e,a)))&&e.some((e=>i(e,a)instanceof Date))?n[a]=o?ye.NUMBER:ye.DATE:e.every((e=>"number"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"number"==typeof i(e,a)))?n[a]=ye.NUMBER:e.every((e=>"boolean"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"boolean"==typeof i(e,a)))?n[a]=ye.BOOLEAN:n[a]=ye.STRING}return n}(r,w,e.schema,"timestamp"===i.dateFormat),f=function(e){return e.map((e=>{if(E(e)){const{x:t,y:r,z:o,m:n}=e,a=[t,r];return e.hasZ&&a.push(o),e.hasM&&a.push(n),qe(a,e)}if(R(e))return Ye(e.points,e);if(A(e))return Ze(e.paths,e);if(I(e))return Ze(e.rings,e);if(G(e)){const t=[e.xmin,e.ymax];return[[t,[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin],t]]}throw new Error("Unsupported geometry type.")}))}(n),y=function(e,t,r,o){const n=[];for(const a of e){const e={};for(const n of t){let t=Ee(a,n,o);if(null==t&&(t=""),o.useFormattedValues)t=t.toString();else{t=Ke(t,r[n],{...o,isDateOnly:"date-only"===a.schema.findFieldByName(n)?.type})}e[n.replaceAll(".","_")]=t}n.push(e)}return n}(r,w,m,i);o.write(y,t,f,((e,r)=>{const o=F.length>1?`${l}_${t.toLowerCase()}`:l;h.file(`${o}.shp`,r.shp.buffer,{binary:!0}),h.file(`${o}.shx`,r.shx.buffer,{binary:!0}),h.file(`${o}.dbf`,r.dbf.buffer,{binary:!0}),h.file(`${o}.prj`,s)}))})));const S=await h.generateAsync({type:"uint8array"});return new Blob([S.buffer],{type:"text/plain"})}export async function kmlToLayerExtensions(e){M("blob",e).isNotMissing();const a=await e.text(),l=(new DOMParser).parseFromString(a,"application/xml"),m=function(e,a,u=!1){const f={};l.querySelectorAll("Style").forEach((e=>{f[`#${e.id}`]=e}));const y=e.querySelector(":scope > name")?.textContent??"Unnamed Container",p=new Map;e.querySelectorAll(":scope > Placemark").forEach(((e,i)=>{const s=e.querySelector("name")?.textContent??"",c=e.querySelector("description")?.textContent??"",l=function(e){const t=e.querySelector("Point > coordinates"),a=e.querySelector("LineString > coordinates"),i=e.querySelector("Polygon");if(t?.textContent){const[e]=parseKMLCoordinates(t.textContent.replace(/ /g,""));return new r(e)}if(a?.textContent)return new n({paths:[parseKMLCoordinates(a.textContent).map((({x:e,y:t})=>[e,t]))]});if(i?.textContent){const e=i.querySelector("outerBoundaryIs > LinearRing > coordinates");if(e?.textContent){const t=[parseKMLCoordinates(e.textContent).map((({x:e,y:t})=>[e,t]))];return new o({rings:t})}}return}(e);if(l?.type){const r=e.querySelector("styleUrl")?.textContent,o=parseKMLSymbol(r?f[r]:e.querySelector("Style"),l.type,a);p.has(l.type)||p.set(l.type,{graphics:[],symbols:[]});let n=function(e,t){for(let r=0;r<e.length;r++)if(Ve(e[r],t))return r;return-1}(p.get(l.type).symbols,o);-1===n&&(p.get(l.type).symbols.push(o),n=p.get(l.type).symbols.length-1),p.get(l.type).graphics.push(new t({geometry:l,attributes:{name:s,description:c,SymbolID:n,OBJECTID:y+i}}))}}));const d=e.querySelectorAll(":scope > Folder, :scope > Document");if(u||1!==p.size||0!==d.length){const e=new N({layer:new s({title:y})});return p.forEach(((t,r)=>{const o=new i({displayField:"name",title:`${r.slice(0,1).toUpperCase()+r.slice(1)}s`,source:t.graphics,renderer:Qe(t.symbols),fields:[new c({name:"OBJECTID",type:"oid",alias:"OBJECTID"}),new c({name:"SymbolID",type:"integer",alias:"SymbolID",editable:!1}),new c({name:"name",type:"string",alias:"name"}),new c({name:"description",type:"string",alias:"description",defaultValue:""})]}),n=new T({layer:o});e.layerExtensions.add(n)})),d.forEach(((t,r)=>{const o=m(t,r);e.layerExtensions.add(o)})),e}{const e=[...p.values()][0],t=new i({displayField:"name",title:y,source:e.graphics,renderer:Qe(e.symbols),fields:[new c({name:"OBJECTID",type:"oid",alias:"OBJECTID"}),new c({name:"SymbolID",type:"integer",alias:"SymbolID",editable:!1}),new c({name:"name",type:"string",alias:"name"}),new c({name:"description",type:"string",alias:"description",defaultValue:""})]});return new T({layer:t})}},u=[];return l.querySelectorAll("kml > Document, kml > Folder").forEach(((e,t)=>{const r=m(e,t,!0);r.layerExtensions.length&&u.push(r)})),u}export async function dxfToLayerExtensions(e,t,r){const{inputSpatialReference:o,outputSpatialReference:n}=t;M("options.dxfBlob",e).isNotMissing(),M("options.inputSpatialReference",o).isNotMissing(),M("options.outputSpatialReference",n).isNotMissing();const a=new ne(o,n,r),i=a.getContext(),c=await e.text(),l=new w;await ee();try{const e=l.parseSync(c);if(!e)throw new Error("DXF parsing failed: parser returned null");i.dxf=e}catch(e){throw e instanceof Error?e:new Error(String(e))}const m=e instanceof File?e.name:"dxf-layer",u=m.replace(/[^a-zA-Z0-9_.-]/g,"_");if(i.fileName=m,i.sanitizedFileName=u,i.subLayers=await a.processAll(),!i.subLayers||0===i.subLayers.length)return[];const f=new s({id:`dxf-group-${u}-${(new Date).getTime()}`,title:m,visible:!0}),y={layer:f,visibilityMode:"independent"};return f.layers.addMany(i.subLayers),[new N(y)]}export async function fgdbToLayerExtensions(e,t){const{displayServiceUrl:r,geoProcessedFgdbData:o}=t;M("options.fgdbBlob",e).isNotMissing(),M("options.displayServiceUrl",r).isNotMissing(),M("options.geoProcessedFgdbData",o).isNotMissing();const n=await ae(o,e,r);return[new O({layer:n})]}export async function shapefileToUploadData(e,t){M("shapefileData",e).isNotMissing();const o=Se(t),n=new Promise(((t,r)=>{const o=new FileReader;o.onload=()=>{t(o.result)},o.onerror=()=>{r(o.error)},o.readAsArrayBuffer(e)})),[{default:i},{default:s}]=await Promise.all([import("jszip"),import("shpjs")]),c=await n,l=await i.loadAsync(new Uint8Array(c)),m=new b;l.forEach(((e,t)=>{t&&m.set(t.name,t)}));const u=l.filter((()=>!0)).map((e=>e.name));let f,y=u.filter((e=>e.endsWith(".shp"))).map((e=>e.substring(0,e.length-4)));if(y=function(e){if(!e.length)return[];let t=e[0];const r=t.match(fe);return r?(t=r[1],e.filter((e=>{const r=e.match(fe);return r&&r[1]===t}))):[t]}(y),u.some((e=>e.endsWith(".prj")))&&!y.every((e=>m.has(`${e}.prj`))))throw new Error("Shapefile zip must contain the same prj file for each separate shapefile");await Promise.all(u.filter((e=>e.endsWith(".prj"))).map((async e=>{const t=await l.file(e).async("string");if(f){if(t!==f)throw new Error("Shapefile zip must contain the same prj file for each separate shapefile")}else f=t})));let p=[],d=[];for(const e of y){if(!m.has(`${e}.shp`)||!m.has(`${e}.shx`)||!m.has(`${e}.dbf`))throw new Error("Shapefile must contain shp, shx, and dbf files.");const t=s.parseShp(await m.get(`${e}.shp`).async("uint8array")),r=s.parseDbf(await m.get(`${e}.dbf`).async("uint8array"));if(r.length!==t.length)throw new Error("Shapefile must contain shp, shx, and dbf files.");p=p.concat(r),d=d.concat(t)}const g=await Promise.all(d.map((e=>async function(e,t){const o=E(e)?function(e){M("geometry.coordinates",e.type).matches("Point"),M("geometry.coordinates",e.coordinates).satisfies((e=>"number"==typeof e||Array.isArray(e)));const[t,o,n]=e.coordinates,i=new r({x:t,y:o,spatialReference:a.WGS84});if(Array.isArray(n)){const[e,t]=n;!e&&!t||e?i.z=e:i.m=t}return i}(e):await K(e);if(t){let e;try{const r=await Y(t);e=new a({wkid:$(r)})}catch{}e||(e=new a({wkt:t})),o.spatialReference=e}return o}(e,f)))),w=geometryTypeHeaders[GeometryFormat.ARCGIS_JSON][0][0];p.forEach(((e,t)=>e[w]=JSON.stringify(g[t].toJSON())));return{data:function(e){const t=e.map((e=>Object.keys(e))).reduce(((e,t)=>e.concat(t.filter((t=>!e.includes(t))))),[]);return[t.map((e=>({raw:e}))),...e.map((e=>t.map((t=>({raw:e[t]})))))]}(p),...o,includeHeaderRow:!0,geometryFormat:GeometryFormat.ARCGIS_JSON,geometryFields:[w],inSpatialReference:g[0]?.spatialReference??a.fromJSON({wkid:4326})}}export async function shapefileToFeatureSet(e,t){M("shapefileData",e).isNotMissing();const r=Se(t);return uploadDataToFeatureSet(await shapefileToUploadData(e,r))}export function getDefaultSymbol(e,t){const r=e%8;let o=["#FFDBFF","#88D6FF","#7F9FC3","#FF8200","#F34A53","#76E3B9","#E7BFFF","#FFC467"][r],n=["#EF3786","#005A99","#2D5070","#790C00","#4C0000","#006543","#6244A9","#904200"][r];if(Math.floor(e/8)%2!=0){const e=o;o=n,n=e}switch(t){case"point":case"multipoint":return new g({color:o,outline:{color:n}});case"polyline":return new d({color:o,width:"2"});case"polygon":return new p({color:o,outline:{color:n}});case"mesh":return new f({symbolLayers:[{type:"fill",material:{color:o},outline:{color:n}}]})}}function we(e){return{escapeFormulaChars:!0,outFields:["*"],generatePrimaryKey:!1,locale:S,detectOid:!e?.primaryKeyField}}function he(e){return{...{includeHeaderRow:!0,inSpatialReference:a.WGS84,...we(e)},...e}}function Fe(e){return{...{includeHeaderRow:!0,inSpatialReference:a.WGS84,...we(e)},...e}}function Se(e){return{...{...we(e)},...e}}function Te(e,t){return t.geometryFormat===GeometryFormat.XYZ?["x","y","z"]:t.geometryFormat===GeometryFormat.XY?["x","y"]:t.geometryFormat===GeometryFormat.LAT_LON?["latitude","longitude"]:t.geometryFormat===GeometryFormat.NONE?[]:["geometry"]}function Ne(e,t,r,o){const n=r.fields.filter((e=>"oid"===e.type)).map((e=>e.name)).toArray();if(o)return n;if(t&&!t.includes("*"))return t.filter((e=>!n.includes(e)));{const t=r.fields.filter((e=>"oid"!==e.type)).map((e=>e.name)).toArray();let o=[];for(const r of e)for(const e of r.attributes.keys())t.includes(e)||n.includes(e)||o.includes(e)||o.push(e);return o=o.sort(),t.concat(o)}}function Oe(e){if(!e)return["*"];const t=e.featureSettings.popupTemplate?.content;if(Array.isArray(t)){const e=new Set;for(const r of t)if("fields"===r.type&&Array.isArray(r.fieldInfos))for(const t of r.fieldInfos)t.visible&&e.add(t.fieldName);if(e.size>0)return Array.from(e)}const r=e.featureSettings.popupTemplate?.fieldInfos;if(Array.isArray(r)){const e=[];for(const t of r)t.visible&&e.push(t.fieldName);if(e.length>0)return e}return["*"]}async function be(e,t){const r=await De(e,t.outSpatialReference);if(t.geometryFormat===GeometryFormat.XYZ){if(!r)return["","",""];if(!E(r))throw new Error("Cannot use geometry format XYZ with non-point geometry");return[r.x,r.y,r.z]}if(t.geometryFormat===GeometryFormat.XY){if(!r)return["",""];if(!E(r))throw new Error("Cannot use geometry format XY with non-point geometry");return[r.x,r.y]}if(t.geometryFormat===GeometryFormat.LAT_LON){if(!r)return["",""];if(!E(r))throw new Error("Cannot use geometry format LAT_LONG with non-point geometry");return[r.y,r.x]}return t.geometryFormat===GeometryFormat.ARCGIS_JSON?r?[JSON.stringify(r.toJSON())]:[""]:t.geometryFormat===GeometryFormat.WKT?r?[await W(r)]:[""]:t.geometryFormat===GeometryFormat.GEO_JSON?r?[JSON.stringify(await Z(r))]:[""]:[]}async function De(e,t){return e?.spatialReference&&!e.spatialReference.equals(t)&&t?(await k([e],t))[0]:e}function Me(e,t){const r=[t.delimiter,se,"\r","\n",t.rowDelimiter];if(t.alwaysQuote||r.some((t=>e.includes(t)))){const t=e.replace(new RegExp(se,"g"),`${se}${se}`);return`${se}${t}${se}`}return e}function xe(e,t){if(null==e)return"";if(!t.useFormattedValues){if("number"==typeof e){const r=t.numberFormat||j.ROUND_TRIP;return H(r,e)}if(e instanceof Date)return"timestamp"===t.dateFormat?e.getTime().toString():L({format:t.dateFormat,timeZone:"UTC",isDateOnly:t.isDateOnly},e);if(e instanceof D)return J({format:t.timeFormat},e)}let r=e.toString();return t.escapeFormulaChars&&(r=Ae(r)),r}function Ee(e,t,r){if(r.useFormattedValues||Re(e,t))return e.presentableAttributes.get(t)??e.attributes.get(t);const o=e.schema.findFieldByName(t)?.type;if(null!=o)switch(o){case"date":case"date-only":case"timestamp-offset":{const r=_(e.attributes.get(t));if(!isNaN(r.getTime()))return r;break}case"time-only":{const r=B(e.attributes.get(t));if(r.isValid)return r;break}}return e.attributes.get(t)??e.presentableAttributes.get(t)}function Re(e,t){return!!te(t,e.schema.typeIdField)||("coded-value"===e.type?.domains?.[t]?.type||"coded-value"===e.schema.findFieldByName(t)?.domain?.type)}function Ae(e){for(const t of ie)if(e.startsWith(t))return`\t${e}`;return e}function Ie(e,t,r){const o=e.startsWith(se),n=e.endsWith(se);if(o&&!n||!o&&n)throw new Error(`Detected invalid CSV: Missing opening or closing quote for value at row:${t} column:${r}`);const a=o?e.substring(1,e.length-1):e;let i=-1;return Ge(a,se,((e,o)=>{if(o===a.length)return!0;if(i<0){if(o!==a.length)return i=o,!0}else if(o===i+1)return i=-1,!0;throw new Error(`Detected invalid CSV: Non-escaped quote for value at row:${t} column:${r}`)})),a.replace(new RegExp(`${se}${se}`,"g"),se)}function Ge(e,t,r){let o,n=!1,a=0,i=0;for(;o=e.indexOf(t,a),!(o<0);){for(let t=a;t<o;)e.substring(t).startsWith(se)?(n=!n,t+=1):t++;const s=o+t.length;if(!n){const e=r(i,o);if(i=s,!e)return}a=s}r(i,e.length)}async function _e(e,t){const r=JSON.parse(e),o=(await import("@arcgis/core/geometry/support/jsonUtils")).fromJSON(r);return r.spatialReference||(o.spatialReference=t),o}async function Le(e,t){const r=await K(JSON.parse(e));return r.spatialReference=t,r}async function Ce(e,t){const r=await X(e);return r.spatialReference=t,r}function ve(e,t,r){const o=r?[r]:geometryTypeHeaders[t];for(const t of o){const r=t.map((t=>e.map((e=>e?.raw?.toString().trim().toLowerCase())).indexOf(t.trim().toLowerCase())));if(r.every((e=>e>=0)))return r}}async function Pe(e,t){return(await Promise.all(e.map((async(e,r)=>{const o=e?.raw;if("string"==typeof o&&""!==o)try{return await t(o,void 0),r}catch{return}})))).find((e=>void 0!==e))}function je(e,t,r){return"inv"===t?"string"==typeof e?parseFloat(e.replaceAll(",","")):e:$({locale:t,format:r},e)}async function Ue(e,t,r){const o=r?e.slice(1):e;if(r){const r=ve(e[0],GeometryFormat.ARCGIS_JSON);if(void 0!==r)for(const[e,n]of de){try{await $e(r[0],n,t,o)}catch{continue}return[e,[r[0]]]}const n=[GeometryFormat.XYZ,GeometryFormat.XY,GeometryFormat.LAT_LON];for(const t of n){const r=ve(e[0],t);if(void 0!==r)return[t,r]}}for(const[e,r]of de){const n=await Pe(o[0],r);if(void 0!==n){try{await $e(n,r,t,o)}catch{continue}return[e,[n]]}}return[GeometryFormat.NONE,[]]}async function $e(e,t,r,o){return{columnIndices:[e],geometries:await Promise.all(o.map((t=>t[e])).map((e=>{if(e?.raw)return t(e.raw.toString(),r)})))}}function He(e,t,r){let o=!1,n=!0,a=!0,i=!0,s=!0,c=!0;const l=new Set,{data:m,includeHeaderRow:u,dateFormat:f,timeFormat:y,primaryKeyField:p,locale:d}=e,g=u?m[0]:[],w=u?m.slice(1):m;for(const e of w){const r=e[t];r?.raw&&(l.add(r.raw),o=!0,n&&(n=Q(r.raw,d)||Number.isNaN(r.raw)),a&&(a=r.raw instanceof Date||_(f||C,r.raw)!==v),s&&(s=_(f||me,r.formatted)!==v),i&&(i=r.raw instanceof D||B(y||z,r.raw).isValid),c&&(c=B({format:y||ue,locale:"en"},r.formatted).isValid))}const h=l.size===w.length;return p&&g[t]?.raw===p||r&&o&&h&&n?"esriFieldTypeOID":o&&c?"esriFieldTypeTimeOnly":o&&s?"esriFieldTypeDate":o&&n?"esriFieldTypeDouble":o&&i?"esriFieldTypeTimeOnly":o&&a?"esriFieldTypeDate":"esriFieldTypeString"}async function Be(e,t,r){const{escapeFormulaChars:o,locale:n,numberFormat:a,dateFormat:i,timeFormat:s}=r;if("esriFieldTypeDouble"===t.type||"esriFieldTypeOID"===t.type)return"number"==typeof e?e:e?je(e,n,a):null;if("esriFieldTypeDate"===t.type){if(e instanceof Date)return e.getTime();if("number"==typeof e){const t=(await import("xlsx")).SSF.parse_date_code(e);return t?new Date(t.y,t.m-1,t.d,t.H,t.M,t.S).getTime():void 0}return""===e?null:_({locale:n,format:i},e).getTime()}if("esriFieldTypeTimeOnly"===t.type){if(e instanceof D)return e.toString();if(e instanceof Date)return new D(e).toString();if("number"==typeof e){const t=(await import("xlsx")).SSF.parse_date_code(e);return t?new D(`${t.H.toString().padStart(2,"0")}:${t.M.toString().padStart(2,"0")}:${t.S.toString().padStart(2,"0")}`).toString():void 0}return""===e?null:B({locale:n,format:s},e).toString()}const c=e?.toString()??"";if(o&&c.startsWith("\t"))for(const e of ie)if(c.length>1&&c.charAt(1)===e)return c.substring(1);return c}function Je(e){switch(e){case P.DATE_SHORT:return"dd/MM/yyyy";case P.DATE_LONG:return"MMMM d, yyyy";case P.TIME_SHORT:return"h:mm AM/PM";case P.TIME_LONG:return"h:mm:ss AM/PM";case P.DATE_TIME_SHORT:case P.DEFAULT:return"MMM d yyyy h:mm AM/PM";case P.DATE_TIME_LONG:return"MMMM d yyyy h:mm AM/PM";case P.FULL:return"dddd, MMMM d yyyy h:mm AM/PM";case P.ISO_8601:case P.ROUND_TRIP:return'yyyy-MM-dd"T"HH:mm:ss';default:{const t=e.replace(/tt/g,"AM/PM");return t.includes("z")&&pe().warn("Warning: Excel will not recognize timezone format 'z', 'zz', or 'zzz'"),t.includes("h")&&!t.includes("AM/PM")&&pe().warn("Warning: Excel will interpret 'h' as 'H' if the format does not have an AM/PM designator"),t}}}function ze(e){switch(e){case P.DATE_SHORT:return"dd/MM/yyyy";case P.DATE_LONG:return"MMMM d, yyyy";case P.DATE_TIME_SHORT:case P.DEFAULT:return"MMM d yyyy";case P.DATE_TIME_LONG:return"MMMM d yyyy";case P.FULL:return"dddd, MMMM d yyyy";case P.ISO_8601:case P.ROUND_TRIP:return"yyyy-MM-dd";default:return e.replace(/TtZzHhmSsUua/g,"")}}function ke(e){switch(e){case U.TIME_SHORT:return"h:mm AM/PM";case U.TIME_LONG:return"h:mm:ss AM/PM";case U.ISO_8601:case U.ROUND_TRIP:return"HH:mm:ss";default:{const t=e.replace(/tt/g,"AM/PM");return t.includes("h")&&!t.includes("AM/PM")&&pe().warn("Warning: Excel will interpret 'h' as 'H' if the format does not have an AM/PM designator"),t}}}function We(e){switch(e){case j.ACCOUNTING:return'_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)';case j.CURRENCY:return'"$"#,##0.00';case j.FIXED_POINT:case j.DEFAULT:return"0.0000";case j.NUMBER:return"#,##0.0000";case j.PERCENT:return"0%";case j.ROUND_TRIP:return"0.00000";default:return e}}function Xe(e,t){if(null==e)return"";if(!t.useFormattedValues){if("number"==typeof e)return e;if(e instanceof Date)return"timestamp"===t.dateFormat?e.getTime():e;if(e instanceof D)return e.toDate()}let r=e.toString();return t.escapeFormulaChars&&(r=Ae(r)),r}function qe(e,t){return 3===e.length&&!t.hasZ&&t.hasM?[e[0],e[1],void 0,e[2]]:e}function Ye(e,t){return e.map((e=>qe(e,t)))}function Ze(e,t){return e.map((e=>Ye(e,t)))}function Ke(e,t,r){switch(t){case ye.NUMBER:return e instanceof Date?e.getTime():$(e);case ye.STRING:return e instanceof Date?L({format:r.dateFormat??P.ROUND_TRIP,timeZone:"UTC",isDateOnly:r.isDateOnly},e):e instanceof D?J({format:r.timeFormat??U.ROUND_TRIP},e):"number"==typeof e?H(r.numberFormat??j.DEFAULT,e):e.toString();case ye.BOOLEAN:return!!e;case ye.DATE:return _(e);default:return e.toString()}}function Ve(e,t){return JSON.stringify(e.toJSON())===JSON.stringify(t.toJSON())}function Qe(e){return 1===e.length?new l({symbol:e[0]}):new m({field:"SymbolID",uniqueValueInfos:[...e.map(((e,t)=>new u({label:t.toString(),symbol:e,value:t})))]})}
1
+ import e from"@arcgis/core/Color.js";import t from"@arcgis/core/Graphic.js";import r from"@arcgis/core/geometry/Point";import o from"@arcgis/core/geometry/Polygon.js";import n from"@arcgis/core/geometry/Polyline.js";import a from"@arcgis/core/geometry/SpatialReference";import i from"@arcgis/core/layers/FeatureLayer.js";import s from"@arcgis/core/layers/GroupLayer.js";import c from"@arcgis/core/layers/support/Field.js";import l from"@arcgis/core/renderers/SimpleRenderer.js";import m from"@arcgis/core/renderers/UniqueValueRenderer.js";import u from"@arcgis/core/renderers/support/UniqueValueInfo.js";import f from"@arcgis/core/symbols/MeshSymbol3D.js";import y from"@arcgis/core/symbols/PictureMarkerSymbol.js";import p from"@arcgis/core/symbols/SimpleFillSymbol.js";import d from"@arcgis/core/symbols/SimpleLineSymbol.js";import g from"@arcgis/core/symbols/SimpleMarkerSymbol.js";import w from"dxf-parser";import{geometryTypeToJson as h}from"../json/GeometryJson.js";import{translate as F}from"../locale/language.js";import{INVARIANT as S}from"../locale.js";import{FeatureCollectionLayerExtension as T}from"../mapping/FeatureCollectionLayerExtension.js";import{GroupLayerExtension as N}from"../mapping/GroupLayerExtension.js";import{MapImageLayerExtension as O}from"../mapping/MapImageLayerExtension.js";import{CaseInsensitiveObservableMap as b}from"../utilities/CaseInsensitiveObservableMap.js";import{Time as x}from"../utilities/Time.js";import{checkArg as D,assertNever as M}from"../utilities/checkArg.js";import{isPoint as E,isMultipoint as R,isPolyline as A,isPolygon as I,isExtent as _}from"../utilities/esri.js";import{parse as G,format as L,DEFAULT_PARSING_FORMATS as C,INVALID_DATE as v}from"../utilities/format/date.js";import{DateFormat as P,NumberFormat as j,TimeFormat as U}from"../utilities/format/formats.js";import{parse as $,format as B}from"../utilities/format/number.js";import{parse as H,format as k,DEFAULT_PARSING_FORMATS as J}from"../utilities/format/time.js";import{project as z,esriToWKT as W,wktToEsri as X,esriWkidToWkt as q,esriWktToWkid as Y,esriToGeoJSON as Z,geoJSONToEsri as K}from"../utilities/geometry.js";import{getLogger as V}from"../utilities/log.js";import{isNumeric as Q}from"../utilities/number.js";import{delay as ee}from"../utilities/promise.js";import{caseInsensitiveEquals as te}from"../utilities/string.js";import{Feature as re}from"./Feature.js";import{FeatureSet as oe}from"./FeatureSet.js";import{DxfEntityProcessor as ne}from"./support/_dxfConverters.js";import{createLpkxLayer as ae}from"./support/_lpkxConverter.js";import{createFgdbLayer as ie}from"./support/fgdbConverter.js";const se=["=","-","+","@"],ce='"',le="\r\n",me="\n",ue=[...C.map(Je),"M/d/yy"],fe=[...J.map(We).map((e=>e.replace("AM/PM","tt")))],ye=/(\w+)_(point|multipoint|polyline|polygon)z?/;var pe;function de(){return V("geocortex.api.data.convert")}!function(e){e.DATE="D",e.NUMBER="N",e.STRING="C",e.BOOLEAN="L"}(pe||(pe={}));export const FIELD_NAME_REGEX=/[^a-zA-Z\d_]/g;export var GeometryFormat;!function(e){e.NONE="NONE",e.WKT="WKT",e.XY="XY",e.XYZ="XYZ",e.LAT_LON="LAT_LONG",e.GEO_JSON="GEO_JSON",e.ARCGIS_JSON="ARCGIS_JSON"}(GeometryFormat||(GeometryFormat={}));export const geometryTypeHeaders={[GeometryFormat.XYZ]:[["x","y","z"]],[GeometryFormat.XY]:[["x","y"]],[GeometryFormat.LAT_LON]:[["latitude","longitude"],["lat","lon"],["lat","long"]],[GeometryFormat.ARCGIS_JSON]:[["geometry"]],[GeometryFormat.GEO_JSON]:[["geometry"]],[GeometryFormat.WKT]:[["geometry"]]};const ge=[[GeometryFormat.ARCGIS_JSON,Le],[GeometryFormat.GEO_JSON,Ce],[GeometryFormat.WKT,ve]],we=new Map(ge);export async function uploadDataToFeatureSet(e){const t=await async function(e){const{data:t,includeHeaderRow:o,geometryFormat:n,geometryFields:a,locale:i,numberFormat:s,inSpatialReference:c}=e,l=o?t.slice(1):t;if(n===GeometryFormat.NONE)return{columnIndices:[]};const m=e=>Ue(e,i,s),u=(e,t)=>{const o=t===GeometryFormat.XYZ,n=t===GeometryFormat.LAT_LON;return{columnIndices:e,geometries:l.map((t=>{if(t.length>=Math.max(...e)&&Q(t[e[0]]?.raw,i)&&Q(t[e[1]]?.raw,i)&&(!o||Q(t[e[2]]?.raw,i)))return new r({x:m(n?t[e[1]].raw:t[e[0]].raw),y:m(n?t[e[0]].raw:t[e[1]].raw),z:o?m(t[e[2]].raw):0,spatialReference:c})}))}},f=async(e,t)=>({columnIndices:[e],geometries:await Promise.all(l.map((t=>t[e])).map((e=>{if(e?.raw)return t(e.raw.toString(),c)})))}),y=async(e,t)=>{switch(t){case GeometryFormat.NONE:return{columnIndices:[0]};case GeometryFormat.LAT_LON:case GeometryFormat.XYZ:case GeometryFormat.XY:return u(e,t);case GeometryFormat.ARCGIS_JSON:return f(e[0],Le);case GeometryFormat.GEO_JSON:return f(e[0],Ce);case GeometryFormat.WKT:return f(e[0],ve);default:return M(t,new Error(`Unknown geometry format "${t}".`))}};if(n){const e=Pe(o?t[0]:t[0].map(((e,t)=>({raw:t.toString()}))),n,o?a:a.map((e=>""+(parseInt(e.match(/\d+/g)[0])-1))));if(o&&void 0===e)throw new Error(`Error parsing file data: Expected geometry columns ${geometryTypeHeaders[n][0].join(",")} are missing for GeometryType.${n}`);return y(e??[0],n)}const[p,d]=await $e(t,c,o);if(p===GeometryFormat.NONE)return{columnIndices:[]};return d.length>1?u(d,p):f(d[0],we.get(p))}(e),o=function(e,t){const{data:r,displayField:o,includeHeaderRow:n,inSpatialReference:a,outSpatialReference:i,generatePrimaryKey:s}=e,c={fields:[]},l=e=>!(!t.columnIndices||0===t.columnIndices.length)&&t.columnIndices.includes(e);let{primaryKeyField:m}=e,u=0;for(let t=0;t<r[0].length;t++){if(l(t))continue;const o=He(e,t,!s&&!m&&!c.fields.find((e=>"esriFieldTypeOID"===e.type)));let a=r[0][t]?.raw?.toString(),i=a?.replace(FIELD_NAME_REGEX,"_");n&&i||(i="field"+ ++u,a=F("gcx.api.data.convert.import-field-alias",u)),c.fields.push({alias:a,name:i,type:o}),"esriFieldTypeOID"===o&&(m=i)}if(c.spatialReference=i??t.geometries?.[0]?.spatialReference??a,t.geometries?.length){const e=t.geometries.filter((e=>void 0!==e)).map((e=>e.type)),r=e[0];c.geometryType=e.every((e=>e===r))?h(r):void 0}if(!c.fields.find((e=>"esriFieldTypeOID"===e.type))){const e=c.fields.length+1,t=!!c.fields.find((e=>"objectid"===e.name.toLowerCase()));m=t?`OBJECTID_${e}`:"OBJECTID",c.fields.push({name:m,alias:m,type:"esriFieldTypeOID"})}return c.displayField=o??c.fields.find((e=>!te(e.name,m)&&"esriFieldTypeString"===e.type))?.name??c.fields.find((e=>!te(e.name,m)))?.name??m,c.primaryKeyField=m,c}(e,t),n=await async function(e,t,r){const{data:o,includeHeaderRow:n,outFields:a,escapeFormulaChars:i,locale:s,numberFormat:c,dateFormat:l,timeFormat:m}=e,{spatialReference:u}=r,f=[],y=n?o.slice(1):o,p=(e,r)=>!t.columnIndices||0===t.columnIndices.length||!t.columnIndices.includes(r);return await Promise.all(y.map((async(e,o)=>{const n=new re;for(let t=0;t<r.fields.length;t++){const u=r.fields[t],f=e.filter(p);if(a.includes("*")||a.filter((e=>te(e,u.name))).length>0){let e=await ke(f[t]?.raw,u,{escapeFormulaChars:i,dateFormat:l,numberFormat:c,timeFormat:m,locale:s});"esriFieldTypeOID"===u.type&&null===e&&(e=o),n.attributes.set(u.name,e)}}t.geometries&&(n.geometry=await De(t.geometries[o],u)),f.push(n)}))),f}(e,t,o);return new oe({features:n,schema:o})}export async function toCsv(e,t){D("featureSet",e).isNotMissing();const r=Array.from(e),o={...{useFormattedValues:!1,alwaysQuote:!1,escapeFormulaChars:!0,delimiter:",",dateFormat:P.ROUND_TRIP,timeFormat:U.ROUND_TRIP,geometryFormat:r.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,includeByteOrderMark:!0,outSpatialReference:a.WGS84,includeHeaderRow:!0,outFields:be(e.source),rowDelimiter:navigator.platform?.startsWith("Win")?le:"\n"},...t},{includeByteOrderMark:n,includeHeaderRow:i,delimiter:s,outFields:c,rowDelimiter:l}=o,m=[];n&&m.push("\ufeff");const u=Ne(r,o),f=Oe(r,c,e.schema,!0),y=Oe(r,c,e.schema,!1);if(i){const e=[];for(const t of u)e.push(Me(t,o));for(const t of f)e.push(Me(t,o));for(const t of y)e.push(Me(t,o));const t=e.join(s)+l;m.push(t)}await Promise.all(r.map((async e=>{const t=[],r=(t,r)=>{const o=Re(e,t,r),n=e.schema.findFieldByName(t)?.type;return Me(Ee(o,{...r,isDateOnly:"date-only"===n}),r)};t.push(...await async function(e,t){let r=await xe(e,t);t.geometryFormat!==GeometryFormat.XYZ&&t.geometryFormat!==GeometryFormat.XY&&t.geometryFormat!==GeometryFormat.LAT_LON||(r=r.map((e=>void 0===e?"":Ee(e,t))));return r.map((e=>""===e?"":Me(e,t)))}(e.geometry,o)),t.push(...f.map((e=>r(e,o)))),t.push(...y.map((e=>r(e,o))));const n=`${t.join(s)}${l}`;m.push(n)})));return new Blob(m,{type:"text/plain",endings:"\n"===l||l===le?"transparent":"native"})}export async function csvToUploadData(e,t){let r;if(D("csvData",e).isNotMissing(),e instanceof Blob){const t=new Promise(((t,r)=>{const o=new FileReader;o.onload=()=>{t(o.result)},o.onerror=()=>{r(o.error)},o.readAsText(e)}));r=await t}else r=e;const o=Fe(t),n=o.rowDelimiter||function(e){let t=me;return Ge(e,le,((r,o)=>(0===r&&o===e.length||(t=le),!1))),t}(r),a=o.delimiter??function(e,t,r){const o=",";if(0===e.length)return o;const n=[];if(Ge(e,t,((t,r)=>(r!==e.length||t!==r)&&(n.push(e.substring(t,r)),n.length<3))),0===n.length)return o;let a=[{delimiter:",",rowsDelimiterOccurrences:[],rowsNumberAdjacentOccurrences:[]},{delimiter:";",rowsDelimiterOccurrences:[]},{delimiter:"|",rowsDelimiterOccurrences:[]},{delimiter:"\t",rowsDelimiterOccurrences:[]},{delimiter:" ",rowsDelimiterOccurrences:[]}].filter((e=>n[0].includes(e.delimiter)));if(0===a.length)return o;for(const e of n)for(const t of a){let o=0,n=0;Ge(e,t.delimiter,((a,i)=>{if(i!==e.length&&o++,","===t.delimiter){const t=e.charAt(i-1),o=e.charAt(i+1);Q(t,r)&&Q(o,r)&&n++}return!0})),t.rowsDelimiterOccurrences.push(o),","===t.delimiter&&t.rowsNumberAdjacentOccurrences.push(n)}if(a=a.filter((e=>e.rowsDelimiterOccurrences.every((t=>e.rowsDelimiterOccurrences[0]===t)))).sort(((e,t)=>t.rowsDelimiterOccurrences[0]-e.rowsDelimiterOccurrences[0])),a.length>1&&","===a[0].delimiter&&null!=r&&r!==S){const e=a[0];if(null!=e&&","===e.delimiter&&","===Intl.NumberFormat(r).formatToParts(1.1).find((e=>"decimal"===e.type))?.value)for(let t=0;t<e.rowsDelimiterOccurrences.length;t++)if(e.rowsDelimiterOccurrences[t]<=e.rowsNumberAdjacentOccurrences[t]){a=a.filter((e=>","!==e.delimiter));break}}if(0===a.length)return o;return a[0].delimiter}(r,n,t.locale),i=function(e,t,r){const o=[],n=(e,t)=>{const o=[];return Ge(e,r,((r,n)=>{const a=e.substring(r,n);return o.push({raw:_e(a,t,o.length)}),!0})),o};if(Ge(e,t,((t,r)=>{const a=e.substring(t,r);return a.length>0&&o.push(n(a,o.length)),!0})),o.length){const e=o[0].length;o.forEach(((t,r)=>{if(t.length!==e)throw new Error(`Detected invalid CSV: Row ${r} does not have expected number of columns: ${e}`)}))}return o}(r,n,a);let{geometryFormat:s,geometryFields:c}=t;if(!s){const[e,t]=await $e(i,o.inSpatialReference,o.includeHeaderRow);s=e,c=t.map((e=>o.includeHeaderRow?i[0][e]?.raw??F("gcx.api.data.convert.import-field-alias",(e+1).toString()):F("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:i,...o,geometryFormat:s,geometryFields:c}}export async function csvToFeatureSet(e,t){const r=Fe(t);return uploadDataToFeatureSet(await csvToUploadData(e,r))}export async function toXLSX(e,t){D("featureSet",e).isNotMissing();const r=Array.from(e),o={...{useFormattedValues:!1,includeHeaderRow:!0,escapeFormulaChars:!0,geometryFormat:r.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,outFields:be(e.source),outSpatialReference:a.WGS84,dateFormat:P.DEFAULT,timeFormat:U.DEFAULT,numberFormat:j.DEFAULT,sheetName:"sheet1"},...t},{outFields:n,includeHeaderRow:i,dateFormat:s,timeFormat:c,numberFormat:l}=o,m=Ne(r,o),u=Oe(r,n,e.schema,!0),f=Oe(r,n,e.schema,!1),y=await import("xlsx"),p=y.utils.sheet_new();let d=!1;if(i){const t=m.concat(u).concat(function(e,t){const r=t?.schema?.fieldExtensions.initializedItems.map((e=>e.field));return e.map((e=>r?.find((t=>te(t.name,e)))?.alias??e))}(f,e.source));d=!0,y.utils.sheet_add_aoa(p,[t],{cellDates:!0})}await Promise.all(r.map((async e=>{const t=[],r=new Set,n=new Set;t.push(...await xe(e.geometry,o));for(const r of u){const n=qe(e.attributes.get(r),o);t.push(n)}for(const a of f){const i=Re(e,a,o);if(i instanceof x){const o=e.schema.findFieldByName(a);"time-only"===o?.type&&r.add(t.length)}else if(i instanceof Date){const r=e.schema.findFieldByName(a);"date-only"===r?.type&&n.add(t.length)}const s=qe(i,o);t.push(s)}if(!t.every((e=>"string"!=typeof e||e.length<=32767)))return void de().warn(`toXLSX cell limit exceeded, feature (${e.primaryKey??e.id}) omitted.`);y.utils.sheet_add_aoa(p,[t],{cellDates:!0,origin:d?-1:void 0}),d=!0;const a=y.utils.decode_range(p["!ref"]);for(let e=a.s.c;e<=a.e.c;e++){const t=p[y.utils.encode_cell({r:a.e.r,c:e})];"d"===t.t?r.has(e)?t.z=We(c??U.ROUND_TRIP):n.has(e)?t.z=ze(s??P.ROUND_TRIP):t.z=Je(s??P.ROUND_TRIP):"n"===t.t&&(t.z=Xe(l))}})));const g={SheetNames:[],Sheets:{}};g.SheetNames.push(o.sheetName),g.Sheets[o.sheetName]=p;const w=y.write(g,{type:"binary",bookType:"xlsx",compression:!0,bookSST:!0,cellDates:!0}),h=new Uint8Array(w.length);for(let e=0;e<w.length;e++)h[e]=w.charCodeAt(e);return new Blob([h.buffer],{type:"text/plain"})}export async function xlsxToUploadData(e,t){D("xlsxData",e).isNotMissing();const r=Se(t),o=await async function(e,t){const r=await import("xlsx"),o=new Promise(((o,n)=>{const a=new FileReader;a.onload=()=>{const e=new Uint8Array(a.result);let n="";for(const t of e)n+=String.fromCharCode(t);const i=r.read(n,{type:"binary",cellDates:!0}),s=t.sheetName||i.SheetNames[0],c=i.Sheets[s];o(c)},a.onerror=()=>{n(a.error)},a.readAsArrayBuffer(e)})),n=await o,a=r.utils.decode_range(n["!ref"]),i=[];for(let e=a.s.r;e<=a.e.r;e++){const t=[];for(let o=a.s.c;o<=a.e.c;o++){const a=n[`${r.utils.encode_cell({r:e,c:o})}`];a&&"d"===a.t&&a.v instanceof Date&&(a.v=new Date(a.v.getTime()+6e4*a.v.getTimezoneOffset())),t.push(a?{raw:a.v,formatted:"s"===a.t?void 0:a.w}:{raw:""})}i.push(t)}return i}(e,r);let{geometryFormat:n,geometryFields:a}=t;if(!n){const[e,t]=await $e(o,r.inSpatialReference,r.includeHeaderRow);n=e,a=t.map((e=>r.includeHeaderRow?o[0][e]?.raw.toString()??F("gcx.api.data.convert.import-field-alias",(e+1).toString()):F("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:o,...r,geometryFormat:n,geometryFields:a}}export async function xlsxToFeatureSet(e,t){D("xlsxData",e).isNotMissing();const r=Se(t);return uploadDataToFeatureSet(await xlsxToUploadData(e,r))}export function kmlHexToEsriColor(t){return e.fromHex(`#${t.match(/.{2}/g).reverse().join("")}`)}export function parseKMLCoordinates(e){return e.trim().split(/\s+/).map((e=>{const[t,r,o]=e.split(",").map(Number);return{x:t,y:r,z:o}}))}export function parseKMLSymbol(t,r,o){if(t){const r=t.querySelector("IconStyle > Icon > href")?.textContent;if(r)return new y({url:r,width:32,height:32});const o=t.querySelector("PolyStyle");if(o){const t=o.querySelector("color")?.textContent,r=t?kmlHexToEsriColor(t):new e([0,0,0,1]);return new p({color:r,outline:{color:[0,0,0,.5],width:1}})}const n=t.querySelector("LineStyle");if(n){const t=n.querySelector("color")?.textContent,r=t?kmlHexToEsriColor(t):new e([0,0,0,1]),o=parseFloat(n.querySelector("width")?.textContent||"1");return new d({color:r,width:o})}}return getDefaultSymbol(o,"polygon"===r?"polygon":"point"===r?"point":"polyline")}export async function toShapefile(e,t){D("featureSet",e).isNotMissing();const[{default:r},o]=await Promise.all([import("jszip"),import("../forked-libs/shp-write/index.js")]),n=Array.from(e),i={...{useFormattedValues:!1,outFields:be(e.source),fileName:e.title||"export"},...t},{outFields:s,outSpatialReference:c,fileName:l}=i,m=e=>e.geometry.hasZ||e.geometry.hasM,u=new Map,f=n.filter((e=>E(e.geometry)));u.set("POINTZ",f.filter(m)),u.set("POINT",f.filter((e=>!m(e))));const y=n.filter((e=>R(e.geometry)));u.set("MULTIPOINTZ",y.filter(m)),u.set("MULTIPOINT",y.filter((e=>!m(e))));const p=n.filter((e=>A(e.geometry)));u.set("POLYLINEZ",p.filter(m)),u.set("POLYLINE",p.filter((e=>!m(e))));const d=n.filter((e=>I(e.geometry)||_(e.geometry)));u.set("POLYGONZ",d.filter(m)),u.set("POLYGON",d.filter((e=>!m(e))));const g=Oe(n,s,e.schema,!0);let w=Oe(n,s,e.schema,!1);w=g.concat(w);const h=new r,F=Array.from(u.keys()).filter((e=>u.get(e).length>0));await Promise.all(F.map((async t=>{const r=u.get(t),n=await Promise.all(r.map((e=>De(e.geometry,c)))),s=await async function(e){const{wkid:t,wkt:r}=e[0].spatialReference;if(!e.every((e=>e.spatialReference.wkid===t&&e.spatialReference.wkt===r)))throw new Error("Cannot create shapefile that contains geometries with different spatial references.");return r??await q(t??a.WGS84.wkid)}(n),m=i.useFormattedValues?Object.assign({},...w.map((e=>({[e]:pe.STRING})))):function(e,t,r,o){const n={};for(const a of t){if(e.some((e=>Ae(e,a)))){n[a]=pe.STRING;continue}const t=r?r.fields.find((e=>te(e.name,a))):void 0;if(t){switch(t.type){case"oid":case"double":case"integer":case"single":case"small-integer":case"big-integer":n[a]=pe.NUMBER;break;case"date":case"timestamp-offset":n[a]=o?pe.NUMBER:pe.DATE;break;default:n[a]=pe.STRING}continue}const i=(e,t)=>e.attributes.get(t)??e.presentableAttributes.get(t);e.every((e=>i(e,a)instanceof Date||void 0===i(e,a)))&&e.some((e=>i(e,a)instanceof Date))?n[a]=o?pe.NUMBER:pe.DATE:e.every((e=>"number"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"number"==typeof i(e,a)))?n[a]=pe.NUMBER:e.every((e=>"boolean"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"boolean"==typeof i(e,a)))?n[a]=pe.BOOLEAN:n[a]=pe.STRING}return n}(r,w,e.schema,"timestamp"===i.dateFormat),f=function(e){return e.map((e=>{if(E(e)){const{x:t,y:r,z:o,m:n}=e,a=[t,r];return e.hasZ&&a.push(o),e.hasM&&a.push(n),Ye(a,e)}if(R(e))return Ze(e.points,e);if(A(e))return Ke(e.paths,e);if(I(e))return Ke(e.rings,e);if(_(e)){const t=[e.xmin,e.ymax];return[[t,[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin],t]]}throw new Error("Unsupported geometry type.")}))}(n),y=function(e,t,r,o){const n=[];for(const a of e){const e={};for(const n of t){let t=Re(a,n,o);if(null==t&&(t=""),o.useFormattedValues)t=t.toString();else{t=Ve(t,r[n],{...o,isDateOnly:"date-only"===a.schema.findFieldByName(n)?.type})}e[n.replaceAll(".","_")]=t}n.push(e)}return n}(r,w,m,i);o.write(y,t,f,((e,r)=>{const o=F.length>1?`${l}_${t.toLowerCase()}`:l;h.file(`${o}.shp`,r.shp.buffer,{binary:!0}),h.file(`${o}.shx`,r.shx.buffer,{binary:!0}),h.file(`${o}.dbf`,r.dbf.buffer,{binary:!0}),h.file(`${o}.prj`,s)}))})));const S=await h.generateAsync({type:"uint8array"});return new Blob([S.buffer],{type:"text/plain"})}export async function kmlToLayerExtensions(e){D("blob",e).isNotMissing();const a=await e.text(),l=(new DOMParser).parseFromString(a,"application/xml"),m=function(e,a,u=!1){const f={};l.querySelectorAll("Style").forEach((e=>{f[`#${e.id}`]=e}));const y=e.querySelector(":scope > name")?.textContent??"Unnamed Container",p=new Map;e.querySelectorAll(":scope > Placemark").forEach(((e,i)=>{const s=e.querySelector("name")?.textContent??"",c=e.querySelector("description")?.textContent??"",l=function(e){const t=e.querySelector("Point > coordinates"),a=e.querySelector("LineString > coordinates"),i=e.querySelector("Polygon");if(t?.textContent){const[e]=parseKMLCoordinates(t.textContent.replace(/ /g,""));return new r(e)}if(a?.textContent)return new n({paths:[parseKMLCoordinates(a.textContent).map((({x:e,y:t})=>[e,t]))]});if(i?.textContent){const e=i.querySelector("outerBoundaryIs > LinearRing > coordinates");if(e?.textContent){const t=[parseKMLCoordinates(e.textContent).map((({x:e,y:t})=>[e,t]))];return new o({rings:t})}}return}(e);if(l?.type){const r=e.querySelector("styleUrl")?.textContent,o=parseKMLSymbol(r?f[r]:e.querySelector("Style"),l.type,a);p.has(l.type)||p.set(l.type,{graphics:[],symbols:[]});let n=function(e,t){for(let r=0;r<e.length;r++)if(Qe(e[r],t))return r;return-1}(p.get(l.type).symbols,o);-1===n&&(p.get(l.type).symbols.push(o),n=p.get(l.type).symbols.length-1),p.get(l.type).graphics.push(new t({geometry:l,attributes:{name:s,description:c,SymbolID:n,OBJECTID:y+i}}))}}));const d=e.querySelectorAll(":scope > Folder, :scope > Document");if(u||1!==p.size||0!==d.length){const e=new N({layer:new s({title:y})});return p.forEach(((t,r)=>{const o=new i({displayField:"name",title:`${r.slice(0,1).toUpperCase()+r.slice(1)}s`,source:t.graphics,renderer:et(t.symbols),fields:[new c({name:"OBJECTID",type:"oid",alias:"OBJECTID"}),new c({name:"SymbolID",type:"integer",alias:"SymbolID",editable:!1}),new c({name:"name",type:"string",alias:"name"}),new c({name:"description",type:"string",alias:"description",defaultValue:""})]}),n=new T({layer:o});e.layerExtensions.add(n)})),d.forEach(((t,r)=>{const o=m(t,r);e.layerExtensions.add(o)})),e}{const e=[...p.values()][0],t=new i({displayField:"name",title:y,source:e.graphics,renderer:et(e.symbols),fields:[new c({name:"OBJECTID",type:"oid",alias:"OBJECTID"}),new c({name:"SymbolID",type:"integer",alias:"SymbolID",editable:!1}),new c({name:"name",type:"string",alias:"name"}),new c({name:"description",type:"string",alias:"description",defaultValue:""})]});return new T({layer:t})}},u=[];return l.querySelectorAll("kml > Document, kml > Folder").forEach(((e,t)=>{const r=m(e,t,!0);r.layerExtensions.length&&u.push(r)})),u}export async function lpkxToLayerExtensions(e,t){const{displayServiceUrl:r,geoProcessedLpkxData:o}=t;D("options.lpkxBlob",e).isNotMissing(),D("options.displayServiceUrl",r).isNotMissing();const n=ae(o,e,r);return[new O({layer:n})]}export async function dxfToLayerExtensions(e,t,r){const{inputSpatialReference:o,outputSpatialReference:n}=t;D("options.dxfBlob",e).isNotMissing(),D("options.inputSpatialReference",o).isNotMissing(),D("options.outputSpatialReference",n).isNotMissing();const a=new ne(o,n,r),i=a.getContext(),c=await e.text(),l=new w;await ee();try{const e=l.parseSync(c);if(!e)throw new Error("DXF parsing failed: parser returned null");i.dxf=e}catch(e){throw e instanceof Error?e:new Error(String(e))}const m=e instanceof File?e.name:"dxf-layer",u=m.replace(/[^a-zA-Z0-9_.-]/g,"_");if(i.fileName=m,i.sanitizedFileName=u,i.subLayers=await a.processAll(),!i.subLayers||0===i.subLayers.length)return[];const f=new s({id:`dxf-group-${u}-${(new Date).getTime()}`,title:m,visible:!0}),y={layer:f,visibilityMode:"independent"};return f.layers.addMany(i.subLayers),[new N(y)]}export async function fgdbToLayerExtensions(e,t){const{displayServiceUrl:r,geoProcessedFgdbData:o}=t;D("options.fgdbBlob",e).isNotMissing(),D("options.displayServiceUrl",r).isNotMissing(),D("options.geoProcessedFgdbData",o).isNotMissing();const n=await ie(o,e,r);return[new O({layer:n})]}export async function shapefileToUploadData(e,t){D("shapefileData",e).isNotMissing();const o=Te(t),n=new Promise(((t,r)=>{const o=new FileReader;o.onload=()=>{t(o.result)},o.onerror=()=>{r(o.error)},o.readAsArrayBuffer(e)})),[{default:i},{default:s}]=await Promise.all([import("jszip"),import("shpjs")]),c=await n,l=await i.loadAsync(new Uint8Array(c)),m=new b;l.forEach(((e,t)=>{t&&m.set(t.name,t)}));const u=l.filter((()=>!0)).map((e=>e.name));let f,y=u.filter((e=>e.endsWith(".shp"))).map((e=>e.substring(0,e.length-4)));if(y=function(e){if(!e.length)return[];let t=e[0];const r=t.match(ye);return r?(t=r[1],e.filter((e=>{const r=e.match(ye);return r&&r[1]===t}))):[t]}(y),u.some((e=>e.endsWith(".prj")))&&!y.every((e=>m.has(`${e}.prj`))))throw new Error("Shapefile zip must contain the same prj file for each separate shapefile");await Promise.all(u.filter((e=>e.endsWith(".prj"))).map((async e=>{const t=await l.file(e).async("string");if(f){if(t!==f)throw new Error("Shapefile zip must contain the same prj file for each separate shapefile")}else f=t})));let p=[],d=[];for(const e of y){if(!m.has(`${e}.shp`)||!m.has(`${e}.shx`)||!m.has(`${e}.dbf`))throw new Error("Shapefile must contain shp, shx, and dbf files.");const t=s.parseShp(await m.get(`${e}.shp`).async("uint8array")),r=s.parseDbf(await m.get(`${e}.dbf`).async("uint8array"));if(r.length!==t.length)throw new Error("Shapefile must contain shp, shx, and dbf files.");p=p.concat(r),d=d.concat(t)}const g=await Promise.all(d.map((e=>async function(e,t){const o=E(e)?function(e){D("geometry.coordinates",e.type).matches("Point"),D("geometry.coordinates",e.coordinates).satisfies((e=>"number"==typeof e||Array.isArray(e)));const[t,o,n]=e.coordinates,i=new r({x:t,y:o,spatialReference:a.WGS84});if(Array.isArray(n)){const[e,t]=n;!e&&!t||e?i.z=e:i.m=t}return i}(e):await K(e);if(t){let e;try{const r=await Y(t);e=new a({wkid:$(r)})}catch{}e||(e=new a({wkt:t})),o.spatialReference=e}return o}(e,f)))),w=geometryTypeHeaders[GeometryFormat.ARCGIS_JSON][0][0];p.forEach(((e,t)=>e[w]=JSON.stringify(g[t].toJSON())));return{data:function(e){const t=e.map((e=>Object.keys(e))).reduce(((e,t)=>e.concat(t.filter((t=>!e.includes(t))))),[]);return[t.map((e=>({raw:e}))),...e.map((e=>t.map((t=>({raw:e[t]})))))]}(p),...o,includeHeaderRow:!0,geometryFormat:GeometryFormat.ARCGIS_JSON,geometryFields:[w],inSpatialReference:g[0]?.spatialReference??a.fromJSON({wkid:4326})}}export async function shapefileToFeatureSet(e,t){D("shapefileData",e).isNotMissing();const r=Te(t);return uploadDataToFeatureSet(await shapefileToUploadData(e,r))}export function getDefaultSymbol(e,t){const r=e%8;let o=["#FFDBFF","#88D6FF","#7F9FC3","#FF8200","#F34A53","#76E3B9","#E7BFFF","#FFC467"][r],n=["#EF3786","#005A99","#2D5070","#790C00","#4C0000","#006543","#6244A9","#904200"][r];if(Math.floor(e/8)%2!=0){const e=o;o=n,n=e}switch(t){case"point":case"multipoint":return new g({color:o,outline:{color:n}});case"polyline":return new d({color:o,width:"2"});case"polygon":return new p({color:o,outline:{color:n}});case"mesh":return new f({symbolLayers:[{type:"fill",material:{color:o},outline:{color:n}}]})}}function he(e){return{escapeFormulaChars:!0,outFields:["*"],generatePrimaryKey:!1,locale:S,detectOid:!e?.primaryKeyField}}function Fe(e){return{...{includeHeaderRow:!0,inSpatialReference:a.WGS84,...he(e)},...e}}function Se(e){return{...{includeHeaderRow:!0,inSpatialReference:a.WGS84,...he(e)},...e}}function Te(e){return{...{...he(e)},...e}}function Ne(e,t){return t.geometryFormat===GeometryFormat.XYZ?["x","y","z"]:t.geometryFormat===GeometryFormat.XY?["x","y"]:t.geometryFormat===GeometryFormat.LAT_LON?["latitude","longitude"]:t.geometryFormat===GeometryFormat.NONE?[]:["geometry"]}function Oe(e,t,r,o){const n=r.fields.filter((e=>"oid"===e.type)).map((e=>e.name)).toArray();if(o)return n;if(t&&!t.includes("*"))return t.filter((e=>!n.includes(e)));{const t=r.fields.filter((e=>"oid"!==e.type)).map((e=>e.name)).toArray();let o=[];for(const r of e)for(const e of r.attributes.keys())t.includes(e)||n.includes(e)||o.includes(e)||o.push(e);return o=o.sort(),t.concat(o)}}function be(e){if(!e)return["*"];const t=e.featureSettings.popupTemplate?.content;if(Array.isArray(t)){const e=new Set;for(const r of t)if("fields"===r.type&&Array.isArray(r.fieldInfos))for(const t of r.fieldInfos)t.visible&&e.add(t.fieldName);if(e.size>0)return Array.from(e)}const r=e.featureSettings.popupTemplate?.fieldInfos;if(Array.isArray(r)){const e=[];for(const t of r)t.visible&&e.push(t.fieldName);if(e.length>0)return e}return["*"]}async function xe(e,t){const r=await De(e,t.outSpatialReference);if(t.geometryFormat===GeometryFormat.XYZ){if(!r)return["","",""];if(!E(r))throw new Error("Cannot use geometry format XYZ with non-point geometry");return[r.x,r.y,r.z]}if(t.geometryFormat===GeometryFormat.XY){if(!r)return["",""];if(!E(r))throw new Error("Cannot use geometry format XY with non-point geometry");return[r.x,r.y]}if(t.geometryFormat===GeometryFormat.LAT_LON){if(!r)return["",""];if(!E(r))throw new Error("Cannot use geometry format LAT_LONG with non-point geometry");return[r.y,r.x]}return t.geometryFormat===GeometryFormat.ARCGIS_JSON?r?[JSON.stringify(r.toJSON())]:[""]:t.geometryFormat===GeometryFormat.WKT?r?[await W(r)]:[""]:t.geometryFormat===GeometryFormat.GEO_JSON?r?[JSON.stringify(await Z(r))]:[""]:[]}async function De(e,t){return e?.spatialReference&&!e.spatialReference.equals(t)&&t?(await z([e],t))[0]:e}function Me(e,t){const r=[t.delimiter,ce,"\r","\n",t.rowDelimiter];if(t.alwaysQuote||r.some((t=>e.includes(t)))){const t=e.replace(new RegExp(ce,"g"),`${ce}${ce}`);return`${ce}${t}${ce}`}return e}function Ee(e,t){if(null==e)return"";if(!t.useFormattedValues){if("number"==typeof e){const r=t.numberFormat||j.ROUND_TRIP;return B(r,e)}if(e instanceof Date)return"timestamp"===t.dateFormat?e.getTime().toString():L({format:t.dateFormat,timeZone:"UTC",isDateOnly:t.isDateOnly},e);if(e instanceof x)return k({format:t.timeFormat},e)}let r=e.toString();return t.escapeFormulaChars&&(r=Ie(r)),r}function Re(e,t,r){if(r.useFormattedValues||Ae(e,t))return e.presentableAttributes.get(t)??e.attributes.get(t);const o=e.schema.findFieldByName(t)?.type;if(null!=o)switch(o){case"date":case"date-only":case"timestamp-offset":{const r=G(e.attributes.get(t));if(!isNaN(r.getTime()))return r;break}case"time-only":{const r=H(e.attributes.get(t));if(r.isValid)return r;break}}return e.attributes.get(t)??e.presentableAttributes.get(t)}function Ae(e,t){return!!te(t,e.schema.typeIdField)||("coded-value"===e.type?.domains?.[t]?.type||"coded-value"===e.schema.findFieldByName(t)?.domain?.type)}function Ie(e){for(const t of se)if(e.startsWith(t))return`\t${e}`;return e}function _e(e,t,r){const o=e.startsWith(ce),n=e.endsWith(ce);if(o&&!n||!o&&n)throw new Error(`Detected invalid CSV: Missing opening or closing quote for value at row:${t} column:${r}`);const a=o?e.substring(1,e.length-1):e;let i=-1;return Ge(a,ce,((e,o)=>{if(o===a.length)return!0;if(i<0){if(o!==a.length)return i=o,!0}else if(o===i+1)return i=-1,!0;throw new Error(`Detected invalid CSV: Non-escaped quote for value at row:${t} column:${r}`)})),a.replace(new RegExp(`${ce}${ce}`,"g"),ce)}function Ge(e,t,r){let o,n=!1,a=0,i=0;for(;o=e.indexOf(t,a),!(o<0);){for(let t=a;t<o;)e.substring(t).startsWith(ce)?(n=!n,t+=1):t++;const s=o+t.length;if(!n){const e=r(i,o);if(i=s,!e)return}a=s}r(i,e.length)}async function Le(e,t){const r=JSON.parse(e),o=(await import("@arcgis/core/geometry/support/jsonUtils")).fromJSON(r);return r.spatialReference||(o.spatialReference=t),o}async function Ce(e,t){const r=await K(JSON.parse(e));return r.spatialReference=t,r}async function ve(e,t){const r=await X(e);return r.spatialReference=t,r}function Pe(e,t,r){const o=r?[r]:geometryTypeHeaders[t];for(const t of o){const r=t.map((t=>e.map((e=>e?.raw?.toString().trim().toLowerCase())).indexOf(t.trim().toLowerCase())));if(r.every((e=>e>=0)))return r}}async function je(e,t){return(await Promise.all(e.map((async(e,r)=>{const o=e?.raw;if("string"==typeof o&&""!==o)try{return await t(o,void 0),r}catch{return}})))).find((e=>void 0!==e))}function Ue(e,t,r){return"inv"===t?"string"==typeof e?parseFloat(e.replaceAll(",","")):e:$({locale:t,format:r},e)}async function $e(e,t,r){const o=r?e.slice(1):e;if(r){const r=Pe(e[0],GeometryFormat.ARCGIS_JSON);if(void 0!==r)for(const[e,n]of ge){try{await Be(r[0],n,t,o)}catch{continue}return[e,[r[0]]]}const n=[GeometryFormat.XYZ,GeometryFormat.XY,GeometryFormat.LAT_LON];for(const t of n){const r=Pe(e[0],t);if(void 0!==r)return[t,r]}}for(const[e,r]of ge){const n=await je(o[0],r);if(void 0!==n){try{await Be(n,r,t,o)}catch{continue}return[e,[n]]}}return[GeometryFormat.NONE,[]]}async function Be(e,t,r,o){return{columnIndices:[e],geometries:await Promise.all(o.map((t=>t[e])).map((e=>{if(e?.raw)return t(e.raw.toString(),r)})))}}function He(e,t,r){let o=!1,n=!0,a=!0,i=!0,s=!0,c=!0;const l=new Set,{data:m,includeHeaderRow:u,dateFormat:f,timeFormat:y,primaryKeyField:p,locale:d}=e,g=u?m[0]:[],w=u?m.slice(1):m;for(const e of w){const r=e[t];r?.raw&&(l.add(r.raw),o=!0,n&&(n=Q(r.raw,d)||Number.isNaN(r.raw)),a&&(a=r.raw instanceof Date||G(f||C,r.raw)!==v),s&&(s=G(f||ue,r.formatted)!==v),i&&(i=r.raw instanceof x||H(y||J,r.raw).isValid),c&&(c=H({format:y||fe,locale:"en"},r.formatted).isValid))}const h=l.size===w.length;return p&&g[t]?.raw===p||r&&o&&h&&n?"esriFieldTypeOID":o&&c?"esriFieldTypeTimeOnly":o&&s?"esriFieldTypeDate":o&&n?"esriFieldTypeDouble":o&&i?"esriFieldTypeTimeOnly":o&&a?"esriFieldTypeDate":"esriFieldTypeString"}async function ke(e,t,r){const{escapeFormulaChars:o,locale:n,numberFormat:a,dateFormat:i,timeFormat:s}=r;if("esriFieldTypeDouble"===t.type||"esriFieldTypeOID"===t.type)return"number"==typeof e?e:e?Ue(e,n,a):null;if("esriFieldTypeDate"===t.type){if(e instanceof Date)return e.getTime();if("number"==typeof e){const t=(await import("xlsx")).SSF.parse_date_code(e);return t?new Date(t.y,t.m-1,t.d,t.H,t.M,t.S).getTime():void 0}return""===e?null:G({locale:n,format:i},e).getTime()}if("esriFieldTypeTimeOnly"===t.type){if(e instanceof x)return e.toString();if(e instanceof Date)return new x(e).toString();if("number"==typeof e){const t=(await import("xlsx")).SSF.parse_date_code(e);return t?new x(`${t.H.toString().padStart(2,"0")}:${t.M.toString().padStart(2,"0")}:${t.S.toString().padStart(2,"0")}`).toString():void 0}return""===e?null:H({locale:n,format:s},e).toString()}const c=e?.toString()??"";if(o&&c.startsWith("\t"))for(const e of se)if(c.length>1&&c.charAt(1)===e)return c.substring(1);return c}function Je(e){switch(e){case P.DATE_SHORT:return"dd/MM/yyyy";case P.DATE_LONG:return"MMMM d, yyyy";case P.TIME_SHORT:return"h:mm AM/PM";case P.TIME_LONG:return"h:mm:ss AM/PM";case P.DATE_TIME_SHORT:case P.DEFAULT:return"MMM d yyyy h:mm AM/PM";case P.DATE_TIME_LONG:return"MMMM d yyyy h:mm AM/PM";case P.FULL:return"dddd, MMMM d yyyy h:mm AM/PM";case P.ISO_8601:case P.ROUND_TRIP:return'yyyy-MM-dd"T"HH:mm:ss';default:{const t=e.replace(/tt/g,"AM/PM");return t.includes("z")&&de().warn("Warning: Excel will not recognize timezone format 'z', 'zz', or 'zzz'"),t.includes("h")&&!t.includes("AM/PM")&&de().warn("Warning: Excel will interpret 'h' as 'H' if the format does not have an AM/PM designator"),t}}}function ze(e){switch(e){case P.DATE_SHORT:return"dd/MM/yyyy";case P.DATE_LONG:return"MMMM d, yyyy";case P.DATE_TIME_SHORT:case P.DEFAULT:return"MMM d yyyy";case P.DATE_TIME_LONG:return"MMMM d yyyy";case P.FULL:return"dddd, MMMM d yyyy";case P.ISO_8601:case P.ROUND_TRIP:return"yyyy-MM-dd";default:return e.replace(/TtZzHhmSsUua/g,"")}}function We(e){switch(e){case U.TIME_SHORT:return"h:mm AM/PM";case U.TIME_LONG:return"h:mm:ss AM/PM";case U.ISO_8601:case U.ROUND_TRIP:return"HH:mm:ss";default:{const t=e.replace(/tt/g,"AM/PM");return t.includes("h")&&!t.includes("AM/PM")&&de().warn("Warning: Excel will interpret 'h' as 'H' if the format does not have an AM/PM designator"),t}}}function Xe(e){switch(e){case j.ACCOUNTING:return'_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)';case j.CURRENCY:return'"$"#,##0.00';case j.FIXED_POINT:case j.DEFAULT:return"0.0000";case j.NUMBER:return"#,##0.0000";case j.PERCENT:return"0%";case j.ROUND_TRIP:return"0.00000";default:return e}}function qe(e,t){if(null==e)return"";if(!t.useFormattedValues){if("number"==typeof e)return e;if(e instanceof Date)return"timestamp"===t.dateFormat?e.getTime():e;if(e instanceof x)return e.toDate()}let r=e.toString();return t.escapeFormulaChars&&(r=Ie(r)),r}function Ye(e,t){return 3===e.length&&!t.hasZ&&t.hasM?[e[0],e[1],void 0,e[2]]:e}function Ze(e,t){return e.map((e=>Ye(e,t)))}function Ke(e,t){return e.map((e=>Ze(e,t)))}function Ve(e,t,r){switch(t){case pe.NUMBER:return e instanceof Date?e.getTime():$(e);case pe.STRING:return e instanceof Date?L({format:r.dateFormat??P.ROUND_TRIP,timeZone:"UTC",isDateOnly:r.isDateOnly},e):e instanceof x?k({format:r.timeFormat??U.ROUND_TRIP},e):"number"==typeof e?B(r.numberFormat??j.DEFAULT,e):e.toString();case pe.BOOLEAN:return!!e;case pe.DATE:return G(e);default:return e.toString()}}function Qe(e,t){return JSON.stringify(e.toJSON())===JSON.stringify(t.toJSON())}function et(e){return 1===e.length?new l({symbol:e[0]}):new m({field:"SymbolID",uniqueValueInfos:[...e.map(((e,t)=>new u({label:t.toString(),symbol:e,value:t})))]})}
@@ -0,0 +1,12 @@
1
+ import MapImageLayer from "@arcgis/core/layers/MapImageLayer";
2
+ import type { GeoProcessedLpkxData } from "./lpkxInterfaces.js";
3
+ /**
4
+ * Opens a feature layer from the geoprocessed LPKX data.
5
+ *
6
+ * @param geoProcessedLpkxData The data resulting from the LPKX geoprocessing
7
+ * task.
8
+ * @param lpkxBlob The original LPKX file blob.
9
+ * @param displayServiceUrl The URL of the Display Service.
10
+ * @returns A MapImageLayer containing the LPKX data.
11
+ */
12
+ export declare function createLpkxLayer(geoProcessedLpkxData: GeoProcessedLpkxData, lpkxBlob: Blob, displayServiceUrl: string): MapImageLayer;
@@ -0,0 +1 @@
1
+ import e from"@arcgis/core/Color.js";import r from"@arcgis/core/geometry/Extent.js";import o from"@arcgis/core/geometry/SpatialReference.js";import t from"@arcgis/core/layers/MapImageLayer";import n from"@arcgis/core/renderers/SimpleRenderer.js";import l from"@arcgis/core/renderers/UniqueValueRenderer";import i from"@arcgis/core/symbols/Font.js";import a from"@arcgis/core/symbols/TextSymbol.js";import{getDefaultSymbol as s}from"../convert.js";let y=0,m="";export function createLpkxLayer(e,i,a){const s=a,y=e.lyrxJson.layerDefinitions,f=e.createdFeatureClasses.split(";"),p=y.flatMap(((r,o)=>{if("CIMGroupLayer"===r.type)return[];const t=function(e){if(!e)return;if("CIMSimpleRenderer"===e.type){const r=c(e.symbol?.symbol);if(!r)return;return new n({symbol:r})}if("CIMUniqueValueRenderer"===e.type){const r=e.fields?.[0];if(!r)return;const o=[];return e.groups?.forEach((e=>{e.classes?.forEach((e=>{const r=c(e.symbol?.symbol);r&&e.values?.forEach((e=>{o.push({value:e.fieldValues?.[0],symbol:r})}))}))})),new l({field:r,uniqueValueInfos:o})}return}(r.renderer),i=r.featureTable?.dataConnection?.dataset,a=f.find((e=>e.endsWith(`_${i}`)));return[{id:o,title:r.name,source:{type:"data-layer",dataSource:{type:"table",workspaceId:e.workspaceId,dataSourceName:a,gdbVersion:""},fields:[]},renderer:t,labelingInfo:u(r,m),showLabels:!0,geometryType:m}]}));p.sort(((e,r)=>{const o=e=>"point"===e?0:"polyline"===e?1:"polygon"===e?2:3;return o(e.geometryType)-o(r.geometryType)}));const b=(i instanceof File?i.name:"lpkx-layer").replace(/[^a-zA-Z0-9_.-]/g,"_"),d=e.bbox||[],g=new r({xmin:d[0],ymin:d[1],xmax:d[2],ymax:d[3],spatialReference:new o({wkid:Number(e.outCrs||o.WebMercator)})});return new t({title:b,url:s,sublayers:p.reverse(),visible:!0,fullExtent:g})}function c(e){if(e)return"CIMPolygonSymbol"===e.type?(m="polygon",function(e){return{type:"cim",data:{type:"CIMSymbolReference",symbol:{type:"CIMPolygonSymbol",symbolLayers:e.symbolLayers??[]}}}}(e)):"CIMLineSymbol"===e.type?(m="polyline",function(e){return{type:"cim",data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:e.symbolLayers??[]}}}}(e)):"CIMPointSymbol"===e.type?(m="point",function(e){return{type:"cim",data:{type:"CIMSymbolReference",symbol:{type:"CIMPointSymbol",symbolLayers:e.symbolLayers}}}}(e)):void 0}function u(e,r){return(e.labelClasses??[]).map((o=>{const t=(n=o.textSymbol?.symbol,n&&"object"==typeof n&&"CIMTextSymbol"===n.type?n:void 0);var n;return{labelExpression:p(o,e),labelPlacement:f(r),where:o.whereClause??"",minScale:o.minScale??0,maxScale:o.maxScale??0,symbol:new a({color:b(t)??s(y++,"polygon").color,haloSize:h(t),haloColor:I(t),kerning:C(t?.kerning),...S(t),font:g(t)})}}))}function f(e){return"point"===e||"Points"===e?"above-right":"polyline"===e||"Polylines"===e?"center-along":"polygon"===e||"Polygons"===e?"always-horizontal":"above-right"}function p(e,r){return e.expression??`$feature.${r.displayField}`}function b(e){const r=e?.symbol?.symbolLayers?.find((e=>"CIMSolidFill"===e.type)),o=r;return d(o?.color)}function d(r){if(!r)return;let o;if(Array.isArray(r))o=r;else{const e=r.values;if(!e)return;"function"==typeof e?o=Array.from(e()):Array.isArray(e)?o=e:Symbol.iterator in Object(e)&&(o=Array.from(e))}if(!o)return;if("CIMHSVColor"===(Array.isArray(r)?void 0:r.type)){let[r=0,t=0,n=0,l=100]=o;t/=100,n/=100;const i=n*(1-t/2),a=0===i||1===i?0:(n-i)/Math.min(i,1-i),s=new e(`hsla(${r}, ${100*a}%, ${100*i}%, ${l/100})`);return[s.r,s.g,s.b,s.a]}return o}function g(e){const r=e?.fontStyleName??"";return new i({family:e?.fontFamilyName,size:e?.height,weight:r.includes("Bold")?"bold":"normal",style:r.includes("Italic")?"italic":"normal"})}function S(e){return{horizontalAlignment:e?.horizontalAlignment?.toLowerCase(),verticalAlignment:e?.verticalAlignment?.toLowerCase()}}function C(e){return"boolean"==typeof e?e:void 0}function h(e){const r=e?.haloSize;if(null==r)return;const o="string"==typeof r?parseFloat(r):Number(r);return Number.isFinite(o)?o:void 0}function I(e){const r=e?.haloSymbol,o=r?.symbolLayers?.find((e=>"CIMSolidFill"===e.type)),t=o;return d(t?.color)}
@@ -0,0 +1,359 @@
1
+ import type CIMSymbol from "@arcgis/core/symbols/CIMSymbol.js";
2
+ import type { CIMSymbolProperties } from "@arcgis/core/symbols/CIMSymbol.js";
3
+ import type PictureMarkerSymbol from "@arcgis/core/symbols/PictureMarkerSymbol.js";
4
+ import type { PictureMarkerSymbolProperties } from "@arcgis/core/symbols/PictureMarkerSymbol.js";
5
+ import type SimpleFillSymbol from "@arcgis/core/symbols/SimpleFillSymbol.js";
6
+ import type { SimpleFillSymbolProperties } from "@arcgis/core/symbols/SimpleFillSymbol.js";
7
+ import type SimpleLineSymbol from "@arcgis/core/symbols/SimpleLineSymbol.js";
8
+ import type { SimpleLineSymbolProperties } from "@arcgis/core/symbols/SimpleLineSymbol.js";
9
+ import type SimpleMarkerSymbol from "@arcgis/core/symbols/SimpleMarkerSymbol.js";
10
+ import type { SimpleMarkerSymbolProperties } from "@arcgis/core/symbols/SimpleMarkerSymbol.js";
11
+ import type TextSymbol from "@arcgis/core/symbols/TextSymbol.js";
12
+ import type { TextSymbolProperties } from "@arcgis/core/symbols/TextSymbol.js";
13
+ import type { CIMLineSymbol, CIMPointSymbol, CIMPolygonSymbol as EsriCIMPolygonSymbol, CIMSolidFill as EsriCIMSolidFill, CIMSolidStroke as EsriCIMSolidStroke, CIMTextSymbol as EsriCIMTextSymbol } from "@arcgis/core/symbols/cim/types.js";
14
+ /**
15
+ * A CIM Point Symbol representation.
16
+ */
17
+ export type CIMPointSymbolLike = Partial<CIMPointSymbol> & {
18
+ type: "CIMPointSymbol";
19
+ };
20
+ /**
21
+ * A CIM Line Symbol representation.
22
+ */
23
+ export type CIMLineSymbolLike = Partial<CIMLineSymbol> & {
24
+ type: "CIMLineSymbol";
25
+ };
26
+ /**
27
+ * A CIM Polygon Symbol representation.
28
+ */
29
+ export type CIMPolygonSymbolLike = Partial<EsriCIMPolygonSymbol> & {
30
+ type: "CIMPolygonSymbol";
31
+ };
32
+ /**
33
+ * A CIM Solid Fill representation.
34
+ */
35
+ export type CIMSolidFillLike = Partial<Omit<EsriCIMSolidFill, "color">> & {
36
+ type: "CIMSolidFill";
37
+ color?: LpkxCimColor;
38
+ };
39
+ /**
40
+ * A CIM Solid Stroke representation.
41
+ */
42
+ export type CIMSolidStrokeLike = Partial<Omit<EsriCIMSolidStroke, "color">> & {
43
+ type: "CIMSolidStroke";
44
+ color?: LpkxCimColor;
45
+ };
46
+ /**
47
+ * A CIM Text Symbol base representation.
48
+ */
49
+ export type CIMTextSymbolBase = Omit<EsriCIMTextSymbol, "fontStyleName">;
50
+ /**
51
+ * A generic wrapper for a Geoprocessing result value.
52
+ */
53
+ export interface GPValue<T> {
54
+ /**
55
+ * The value of the result.
56
+ */
57
+ value: T;
58
+ }
59
+ /**
60
+ * The result of parsing a .lyrx file, containing layer definitions.
61
+ */
62
+ export interface LyrxResult {
63
+ /**
64
+ * The value of the layerDefinitions from result.
65
+ */
66
+ layerDefinitions: LyrxLayerDefinition[];
67
+ }
68
+ /**
69
+ * Data structure holding results from the LPKX geoprocessing task.
70
+ */
71
+ export interface GeoProcessedLpkxData {
72
+ /**
73
+ * The parsed Lyrx result.
74
+ */
75
+ lyrxJson: LyrxResult;
76
+ /**
77
+ * The data source result.
78
+ */
79
+ createdFeatureClasses: string;
80
+ /**
81
+ * The workspace result.
82
+ */
83
+ workspaceId: string;
84
+ /**
85
+ * The bounding box result.
86
+ */
87
+ bbox: number[];
88
+ /**
89
+ * The output CRS result.
90
+ */
91
+ outCrs?: string;
92
+ }
93
+ /**
94
+ * Definition of a layer within the Lyrx structure.
95
+ */
96
+ export interface LyrxLayerDefinition {
97
+ /**
98
+ * The name of the layer.
99
+ */
100
+ name: "Points" | "Polylines" | "Polygons";
101
+ /**
102
+ * The renderer configuration for the layer.
103
+ */
104
+ renderer?: LpkxCimRenderer;
105
+ /**
106
+ * The label classes associated with the layer.
107
+ */
108
+ labelClasses?: LpkxCimLabelClass[];
109
+ /**
110
+ * The display field name for the layer.
111
+ */
112
+ displayField?: string;
113
+ /**
114
+ * The feature table configuration for the layer.
115
+ */
116
+ featureTable?: {
117
+ dataConnection?: {
118
+ dataset?: string;
119
+ };
120
+ };
121
+ }
122
+ /**
123
+ * Interface for CIM (Cartographic Information Model) Renderer.
124
+ */
125
+ export interface LpkxCimRenderer {
126
+ /**
127
+ * The type of the renderer.
128
+ */
129
+ type: "CIMUniqueValueRenderer" | "CIMSimpleRenderer";
130
+ /**
131
+ * The fields used for the renderer.
132
+ */
133
+ fields?: string[];
134
+ /**
135
+ * The groups of renderer classes.
136
+ */
137
+ groups?: LpkxCimRendererGroup[];
138
+ /**
139
+ * The symbol associated with the renderer.
140
+ */
141
+ symbol?: LpkxCimSymbolReference;
142
+ }
143
+ /**
144
+ * Group of classes in a CIM renderer.
145
+ */
146
+ export interface LpkxCimRendererGroup {
147
+ /**
148
+ * The classes within this group.
149
+ */
150
+ classes?: LpkxCimRendererClass[];
151
+ }
152
+ /**
153
+ * A classification class in a CIM renderer.
154
+ */
155
+ export interface LpkxCimRendererClass {
156
+ /**
157
+ * The symbol associated with this class.
158
+ */
159
+ symbol?: LpkxCimSymbolReference;
160
+ /**
161
+ * The values that define this class.
162
+ */
163
+ values: {
164
+ fieldValues: string[];
165
+ }[];
166
+ /**
167
+ * The label for the class.
168
+ */
169
+ label?: string;
170
+ }
171
+ /**
172
+ * Interface for a CIM Symbol reference.
173
+ */
174
+ export interface LpkxCimSymbolReference {
175
+ /**
176
+ * The symbol.
177
+ */
178
+ symbol: LpkxCimSymbol;
179
+ }
180
+ /**
181
+ * Interface for a CIM Symbol.
182
+ */
183
+ export type LpkxCimSymbol = CIMPointSymbolLike | CIMLineSymbolLike | CIMPolygonSymbolLike;
184
+ /**
185
+ * Interface for a solid fill symbol layer.
186
+ */
187
+ export type LpkxCimSolidFill = CIMSolidFillLike;
188
+ /**
189
+ * Interface for a solid stroke symbol layer.
190
+ */
191
+ export type LpkxCimSolidStroke = CIMSolidStrokeLike;
192
+ /**
193
+ * Interface for CIM color values.
194
+ */
195
+ export type LpkxCimColorValues = number[] | Iterable<number> | (() => Iterable<number>);
196
+ /**
197
+ * Interface for a CIM Color Object.
198
+ */
199
+ export interface LpkxCimColorObject {
200
+ /**
201
+ * The color values.
202
+ */
203
+ values?: LpkxCimColorValues;
204
+ }
205
+ /**
206
+ * Union type for CIM color values, can be a number array or a color object.
207
+ */
208
+ export type LpkxCimColor = number[] | LpkxCimColorObject;
209
+ /**
210
+ * Interface for label classes in CIM.
211
+ */
212
+ export interface LpkxCimLabelClass {
213
+ /**
214
+ * The label expression.
215
+ */
216
+ expression?: string;
217
+ /**
218
+ * The SQL where clause to filter labels.
219
+ */
220
+ whereClause?: string;
221
+ /**
222
+ * The minimum scale at which labels are visible.
223
+ */
224
+ minScale?: number;
225
+ /**
226
+ * The maximum scale at which labels are visible.
227
+ */
228
+ maxScale?: number;
229
+ /**
230
+ * The text symbol used for labeling.
231
+ */
232
+ textSymbol?: {
233
+ symbol: LpkxCimTextSymbol;
234
+ };
235
+ }
236
+ /**
237
+ * Interface for text symbols in CIM.
238
+ */
239
+ export type LpkxCimTextSymbol = Omit<CIMTextSymbolBase, "symbol"> & {
240
+ /**
241
+ * The font family name.
242
+ */
243
+ fontFamilyName?: string;
244
+ /**
245
+ * The font style name.
246
+ */
247
+ fontStyleName?: string;
248
+ /**
249
+ * The height of the text.
250
+ */
251
+ height?: number;
252
+ /**
253
+ * The horizontal alignment of the text.
254
+ */
255
+ horizontalAlignment?: string;
256
+ /**
257
+ * The vertical alignment of the text.
258
+ */
259
+ verticalAlignment?: string;
260
+ /**
261
+ * The polygon symbol used for text background or halo.
262
+ */
263
+ symbol?: LpkxCimPolygonSymbol;
264
+ /**
265
+ * Whether kerning is enabled.
266
+ */
267
+ kerning?: boolean;
268
+ };
269
+ /**
270
+ * Interface for CIM Polygon Symbol.
271
+ */
272
+ export type LpkxCimPolygonSymbol = Omit<CIMPolygonSymbolLike, "symbolLayers"> & {
273
+ /**
274
+ * The layers that make up the symbol.
275
+ */
276
+ symbolLayers?: (LpkxCimSolidFill | LpkxCimSolidStroke)[];
277
+ };
278
+ /**
279
+ * Union type for supported Esri symbols.
280
+ */
281
+ export type EsriSupportedSymbol = SimpleFillSymbol | SimpleLineSymbol | SimpleMarkerSymbol | PictureMarkerSymbol | TextSymbol | CIMSymbol;
282
+ /**
283
+ * Union type for supported Esri symbol property bags. Prefer these when
284
+ * constructing renderers.
285
+ */
286
+ /**
287
+ * Simple fill symbol properties with type discriminator.
288
+ */
289
+ export type SimpleFillSymbolPropsWithType = SimpleFillSymbolProperties & {
290
+ type: "simple-fill";
291
+ };
292
+ /**
293
+ * Simple line symbol properties with type discriminator.
294
+ */
295
+ export type SimpleLineSymbolPropsWithType = SimpleLineSymbolProperties & {
296
+ type: "simple-line";
297
+ };
298
+ /**
299
+ * Simple marker symbol properties with type discriminator.
300
+ */
301
+ export type SimpleMarkerSymbolPropsWithType = SimpleMarkerSymbolProperties & {
302
+ type: "simple-marker";
303
+ };
304
+ /**
305
+ * Picture marker symbol properties with type discriminator.
306
+ */
307
+ export type PictureMarkerSymbolPropsWithType = PictureMarkerSymbolProperties & {
308
+ type: "picture-marker";
309
+ };
310
+ /**
311
+ * Text symbol properties with type discriminator.
312
+ */
313
+ export type TextSymbolPropsWithType = TextSymbolProperties & {
314
+ type: "text";
315
+ };
316
+ /**
317
+ * CIM symbol properties with type discriminator.
318
+ */
319
+ export type CIMSymbolPropsWithType = CIMSymbolProperties & {
320
+ type: "cim";
321
+ };
322
+ /**
323
+ * Union type for supported Esri symbol property bags with type discriminators.
324
+ */
325
+ export type EsriSupportedSymbolProps = SimpleFillSymbolPropsWithType | SimpleLineSymbolPropsWithType | SimpleMarkerSymbolPropsWithType | PictureMarkerSymbolPropsWithType | TextSymbolPropsWithType | CIMSymbolPropsWithType;
326
+ /**
327
+ * Represents a CIM fill-like object with an optional color property.
328
+ */
329
+ export interface CIMFillLike {
330
+ /**
331
+ * The color of the fill.
332
+ */
333
+ color?: ColorInput;
334
+ }
335
+ /**
336
+ * An array of numbers representing a color.
337
+ */
338
+ export type ColorArray = number[];
339
+ /**
340
+ * Represents the possible types for color values.
341
+ */
342
+ export type ColorValues = number[] | Iterable<number> | (() => Iterable<number>);
343
+ /**
344
+ * An object representation of a color, with an optional type and its values.
345
+ */
346
+ export interface ColorObject {
347
+ /**
348
+ * The type of the color (e.g., "CIMHSVColor").
349
+ */
350
+ type?: string;
351
+ /**
352
+ * The color values.
353
+ */
354
+ values?: ColorValues;
355
+ }
356
+ /**
357
+ * A union type representing the different ways a color can be input.
358
+ */
359
+ export type ColorInput = ColorArray | ColorObject;
@@ -0,0 +1 @@
1
+ export{};