@vertigis/arcgis-extensions 41.0.0 → 41.2.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.
- package/data/Feature.d.ts +2 -1
- package/data/Feature.js +1 -1
- package/data/FeatureSettings.js +1 -1
- package/data/FieldExtension.js +1 -1
- package/data/Schema.js +1 -1
- package/data/convert.js +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/data_Feature.Feature.html +5 -5
- package/docs/html/classes/data_FeatureList.FeatureList.html +4 -4
- package/docs/html/classes/data_FeatureSet.FeatureSet.html +4 -4
- package/docs/html/interfaces/tasks_identify_IdentifyOptions.IdentifyOptions-1.html +8 -0
- package/docs/html/variables/version.version.html +1 -1
- package/mapping/GeoRSSLayerExtension.js +1 -1
- package/package.json +1 -1
- package/portal/FeatureLayer.js +1 -1
- package/tasks/identify/ArcGISSublayerQueryIdentifyProvider.js +1 -1
- package/tasks/identify/CSVLayerClientSideQueryIdentifyProvider.js +1 -1
- package/tasks/identify/ClientSideIdentifyProvider.js +1 -1
- package/tasks/identify/FeatureLayerQueryIdentifyProvider.js +1 -1
- package/tasks/identify/GeoJSONLayerClientSideQueryIdentifyProvider.js +1 -1
- package/tasks/identify/GeoRSSLayerIdentifyProvider.js +1 -1
- package/tasks/identify/HitTestIdentifyProvider.js +1 -1
- package/tasks/identify/IdentifyOptions.d.ts +5 -0
- package/tasks/identify/ImageryLayerIdentifyProvider.js +1 -1
- package/tasks/identify/KMLLayerQueryIdentifyProvider.js +1 -1
- package/tasks/identify/MapNotesSublayerQueryIdentifyProvider.js +1 -1
- package/tasks/identify/RouteLayerQueryIdentifyProvider.js +1 -1
- package/tasks/identify/SceneLayerClientSideIdentifyProvider.js +1 -1
- package/tasks/identify/SubtypeSublayerQueryIdentifyProvider.js +1 -1
- package/tasks/identify/WMSSublayerIdentifyProvider.js +1 -1
- package/tasks/search/_utilities.js +1 -1
- package/utilities/string.js +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/data/Feature.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { GeometryJson } from "../json/GeometryJson.js";
|
|
|
9
9
|
import type { CancelToken } from "../support/Cancellable.js";
|
|
10
10
|
import type { PropertyDefs } from "../support/Serializable.js";
|
|
11
11
|
import type { WatchCallback } from "../support/esri.js";
|
|
12
|
+
import { CaseInsensitiveObservableMap } from "../utilities/CaseInsensitiveObservableMap.js";
|
|
12
13
|
import { ObservableMap } from "../utilities/ObservableMap.js";
|
|
13
14
|
import { ReadOnlyMap } from "../utilities/ReadOnlyMap.js";
|
|
14
15
|
import { type FormatOptions as FormatOptionsBase } from "../utilities/string.js";
|
|
@@ -98,7 +99,7 @@ export declare class Feature extends EntityBase<FeatureProperties> {
|
|
|
98
99
|
/**
|
|
99
100
|
* The feature's attributes, keyed by field name.
|
|
100
101
|
*/
|
|
101
|
-
readonly attributes:
|
|
102
|
+
readonly attributes: CaseInsensitiveObservableMap<unknown>;
|
|
102
103
|
/**
|
|
103
104
|
* The feature's geometry. For non-spatial features, this will be undefined.
|
|
104
105
|
*/
|
package/data/Feature.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__decorate as e}from"tslib";import t from"@arcgis/core/Graphic";import s from"@arcgis/core/core/Collection";import{fromJSON as i}from"@arcgis/core/geometry/support/jsonUtils";import{EntityBase as r}from"../Entity.js";import{Hyperlink as a}from"../Hyperlink.js";import{InvalidOperationError as o}from"../InvalidOperationError.js";import{ItemType as n}from"../ItemType.js";import{serializable as h}from"../support/Serializable.js";import{CaseInsensitiveObservableMap as l}from"../utilities/CaseInsensitiveObservableMap.js";import{MapTransformCollection as p}from"../utilities/MapTransformCollection.js";import{ObservableMap as u}from"../utilities/ObservableMap.js";import{ReadOnlyMap as c}from"../utilities/ReadOnlyMap.js";import{flatten as m,groupBy as f}from"../utilities/array.js";import{checkArg as d}from"../utilities/checkArg.js";import{compare as g}from"../utilities/collection.js";import{parse as y,esriFormatToGeocortexFormat as _}from"../utilities/date.js";import{isCodedValueDomain as b,isGeometry as x}from"../utilities/esri.js";import{fieldWithArcadeXRegex as w,fieldWithRelationshipRegex as F}from"../utilities/field.js";import{some as v,map as I,concat as z,forEach as A,find as E}from"../utilities/iterable.js";import{getLogger as S}from"../utilities/log.js";import{parse as j,NumberFormat as T}from"../utilities/number.js";import{map as k}from"../utilities/promise.js";import{caseInsensitiveEquals as R}from"../utilities/string.js";import{format as C}from"../utilities/string.js";import{onCollectionPropertyChange as M}from"../utilities/watch.js";import{FeatureSettings as O}from"./FeatureSettings.js";import{Schema as N}from"./Schema.js";const P=S("geocortex.api.data.Feature");export const SCORE_FIELD="_score";export const SCORE_FIELD_ORIGINAL="_score_original";let V=class extends r{get geometry(){return this._geometry}set geometry(e){this.notifyChange("geometryType"),this._geometry=x(e)||!e?e:i(e),this.schema.spatialReference=this._geometry?.spatialReference}get geometryType(){return this.geometry?this.geometry.type:void 0}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.schema.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0),this.notifyChange("attachmentsInitialized"),this.notifyChange("relatedFeaturesInitialized")}get primaryKey(){const e=this.attributes.get(this.schema.primaryKeyField);return null!=e?`${e}`:void 0}get hasGlobalId(){return!!this.schema.fields.find((e=>"global-id"===e.type))}get globalId(){const e=this.schema.fields.find((e=>"global-id"===e.type));return e?this.attributes.get(e.name):void 0}set globalId(e){const t=this.schema.fields.find((e=>"global-id"===e.type));if(!t)throw new o("Cannot set global ID on feature -- no global ID field.");this.attributes.set(t.name,e)}get presentableAttributes(){return this._presentableAttributes=this._presentableAttributes||new G(this),this._presentableAttributes}get title(){return this.format(this._title||"")}get description(){return this.format(this._description)}get hyperlinks(){return this._hyperlinks||(this._hyperlinks=new B(this))}get relatedFeatures(){return this._relatedFeatures}get type(){if(this.schema.typeIdField&&this.attributes.has(this.schema.typeIdField)){const e=this.attributes.get(this.schema.typeIdField);return this.schema.types.find((t=>t.id===e))}}get attachmentsInitialized(){return!this.source||this._attachmentsInitialized}get relatedFeaturesInitialized(){return!this.source||this.source.relationships.every((e=>this._initializedRelationships.has(e)))}get expressionsInitialized(){return!this.settings.popupTemplate?.expressionInfos?.length||this._expressionsInitialized}get _hydrationStatus(){return this._featureHydrationStatus?this._featureHydrationStatus:this.source?.capabilities?.supportsQuery&&1===this.attributes.size&&void 0!==this.primaryKey?"dehydrated":"hydrated"}set _hydrationStatus(e){this._featureHydrationStatus=e}get _key(){return`${this.source?.id}//${this.primaryKey??this.globalId??this.id}`}get _title(){let e;return this.settings.popupTemplate&&(e="function"==typeof this.settings.popupTemplate.title?this.settings.popupTemplate.title():this.settings.popupTemplate.title),e||this.schema.displayField&&this.presentableAttributes.get(this.schema.displayField)||""}get _description(){if(this.settings.popupTemplate?.content){if("string"==typeof this.settings.popupTemplate.content)return this.settings.popupTemplate.content;if(Array.isArray(this.settings.popupTemplate.content)){const e=this.settings.popupTemplate.content.find((e=>"text"===e.type));if(e)return e.text}}return""}constructor(e){super(e),this._itemType=n.FEATURE,this._expressionFieldValues=new u,this._expressionValuesUpdatePending=!1,this._attachmentsInitialized=!1,this._expressionsInitialized=!1,this._initializedRelationships=new WeakSet,this.settings=new O,this.settings._setFeature(this),this.schema=new N,this.schema._featureSettings=this.settings,this.attachments=new s,this.attributes=new l,this._relatedFeatures=new u,this.expressionFieldValues=new $(this._expressionFieldValues,this),M(this,"source.relationships",(()=>{this.notifyChange("relatedFeaturesInitialized")}),!0),this.settings.watch("popupTemplate",((e,t)=>{e!==t&&(this._expressionsInitialized=!1,this.notifyChange("expressionsInitialized"))}),!0)}format(e,...t){let s="string"==typeof e?{format:e}:e;d("options",s).isNotMissing();const{format:i}=s;d("format",i).isNotMissing();let r=s.format.replace(H,J);return r=r.replace(L,((e,t,i,r,a)=>q(this,t||i,r,{...s,format:a?`{0:${a}}`:"{0}"}))),r=r.replace(Z,"{{"),s={...s},s.format=r,C(s,...t)}clearExpressionInfos(){this._expressionFieldValues.clear()}toGraphic(){return toGraphic(this)}async fetchExpressionInfos(e=!1){const{expressionInfos:t}=this.settings.popupTemplate??{};if(!t)return;const{runAsyncArcadeExpression:s}=await import("../utilities/arcade.js");if(await Promise.all(t.map((async e=>{try{const t=this.source?.layer??this.source?.sublayer;let i=this.source?.mapExtension;if(!i){const e=this.source?.layerExtension;i=e?.mapExtension}this._expressionFieldValues.set(e.name,await s(e.expression,{layer:t,map:i?.map,feature:this,spatialReference:this.schema.spatialReference}))}catch(t){t instanceof Error&&P.error({message:"Error evaluating expression '{0}': {1}.",error:t},e.name,t.message),this._expressionFieldValues.set(e.name,Q)}}))),e)return this.attributes.on("change",(async e=>{this._expressionValuesUpdatePending||(this._expressionValuesUpdatePending=!0,setTimeout((async()=>{this._expressionValuesUpdatePending=!1,await this.fetchExpressionInfos()}),0))}));this._expressionsInitialized=!0,this.notifyChange("expressionsInitialized")}async fetchRelatedFeatures(e,t){if(!this.source)return;let s=[];if(e){const t=new Set(Array.isArray(e)?e:[e]);for(const e of t){const t="string"==typeof e?this.source.relationships.find((t=>t.id===e)):e;if(!t||!this.source.relationships.includes(t))throw new o("Relationship not found in feature source.");s.push(t)}}else s=this.source.relationships.toArray();const i=await k(s,(async e=>[e,await(async()=>{const s=await e.getRelatedFeatures(this,t);return this._initializedRelationships.add(e),s})()]));for(const e of i)this._relatedFeatures.set(e[0],e[1]);this.notifyChange("relatedFeaturesInitialized")}async fetchAttachments(){if(this.source){const e=await this.source.getAttachments(this);g(this.attachments,e,{equals:(e,t)=>e.id===t.id,onMissing:(e,t)=>this.attachments.remove(e),onNew:(e,t)=>{this.attachments.add(e)},onMatch:(e,t,s,i)=>{this.attachments.splice(s,1,t)}}),this._attachmentsInitialized=!0,this.notifyChange("attachmentsInitialized")}}async addAttachment(e){return this.source?.addAttachment(this,e)}async deleteAttachments(e){return this.source?.deleteAttachments(this,e)}_getSerializableProperties(){return{...super._getSerializableProperties(),attributes:{serializeModes:["project"],serialize:e=>{const t={};if("project"===e&&this.primaryKey&&(this.source?.capabilities).supportsQuery)t[this.schema.primaryKeyField]=this.primaryKey;else for(const[e,s]of this.attributes.entries())t[e]=s;return t},deserialize:e=>{if(this.attributes.clear(),e instanceof Map)e.forEach(((e,t)=>{this.attributes.set(t,e)}));else for(const[t,s]of Object.entries(e))this.attributes.set(t,s)}},geometry:{serializeModes:["project"],serialize:e=>"project"===e&&(this.source?.capabilities).supportsQuery?this.getDefault("geometry"):this.geometry?.toJSON(),deserialize:e=>{this.geometry=e}},settings:{serializeModes:["project"],serialize:e=>"project"===e&&(this.source?.capabilities).supportsQuery?this.getDefault("settings"):this.settings.toJSON(e)},schema:{serializeModes:["project"],serialize:e=>"project"===e&&(this.source?.capabilities).supportsQuery?this.getDefault("schema"):this.schema.toJSON(e)},source:["project"]}}_watchProperty(e,t,s,i){if("title"===e||"description"===e){const r=super._watchProperty(e,t,s,i),a="title"===e?"settings.popupTemplate.title":"settings.popupTemplate.content",o=this.watch(a,(()=>{this.notifyChange(e)})),n=this.presentableAttributes.on("change",(()=>{this.notifyChange(e)}));return{remove(){r.remove(),o.remove(),n.remove()}}}return super._watchProperty(e,t,s,i)}async _onInitialize(){const e=this._findRelationshipIds(this._title,this._description),t=this.source?this.source.relationships.map((e=>e.id)).toArray():[],s=[];for(const i of e)t.includes(i)?s.push(this.fetchRelatedFeatures(i)):P.error("Could not find relationship '{0}' referenced in feature title or description.",i);await Promise.all(s)}_findRelationshipIds(...e){const t=[];for(const s of e){let e;const i=s.replace(H,J);for(;e=K.exec(i),null!==e;){const s=e[0];t.includes(s)||t.push(e[1])}}return t}};V=e([h],V);export{V as Feature};export function toFeature(e,t){const s=new V(t);if(e.attributes)for(const t of Object.keys(e.attributes))s.attributes.set(t,e.attributes[t]);return s.geometry=e.geometry,e.popupTemplate&&(s.settings.popupTemplate=e.popupTemplate),s}export function toGraphic(e){const s=new t;s.attributes={};for(const t of e.attributes.keys())s.attributes[t]=e.attributes.get(t);return e.source?.layer&&(s.layer=e.source?.layer),s.geometry=e.geometry,e.settings.popupTemplate&&(s.popupTemplate=e.settings.popupTemplate),s}const D="Presentable attributes are read-only.",U="Feature hyperlinks are read-only. Modify the feature's hyperlink templates instead.";class $ extends c{constructor(e,t){super(e),this._feature=t}get(e){if(!super.has(e)){const{spatialReference:t}=this._feature.schema,s=this._feature.settings.popupTemplate?.expressionInfos?.find((t=>t.name===e));if(!s)return;(async()=>{const{isArcadeScriptAsync:i,runAsyncArcadeExpression:r,arcadeScriptUsesGeometry:a,runArcadeExpression:o}=await import("../utilities/arcade.js");try{if(i(s.expression,t)){const i=this._feature.source?.layer??this._feature.source?.sublayer;let a=this._feature.source?.mapExtension;if(!a){const e=this._feature.source?.layerExtension;a=e?.mapExtension}this._originalMap.set(e,await r(s.expression,{feature:this._feature,layer:i,map:a?.map,spatialReference:t}))}else{if(a(s.expression,t)){const{enableGeometrySupport:e}=await import("@arcgis/core/arcade/arcade");await e()}this._originalMap.set(e,o(s.expression,{feature:this._feature,spatialReference:t}))}}catch(t){t instanceof Error&&P.error({message:"Error evaluating expression '{0}': {1}.",error:t},e,t.message),this._originalMap.set(e,Q)}})()}return super.get(e)}}class G extends c{get size(){return this._feature.attributes.size+this._feature.schema.fields._expressionFieldsLength}constructor(e){super(new u),this._feature=e}clear(){throw new o(D)}delete(e){throw new o(D)}forEach(e,t){d("callback",e).isNotMissing();for(const s of this.keys())e.call(t,this.get(s),s,this)}get(e){const t=this._getFieldExtensionFormat(e);return this._formatAttribute(e,t)}has(e){return v(this.keys(),(t=>R(t,e)))}set(...e){throw new o(D)}*entries(){yield*I(this.keys(),(e=>[e,this.get(e)]))}*keys(){const e=this._feature.schema.fields.expressionFields.map((e=>e.name)),t=[];this._feature.source?.relationships&&this._feature.source.relationships.filter((e=>"one-to-one"===e.cardinality||"many-to-one"===e.cardinality)).forEach((e=>t.push(...e.relatedSource.schema.fields.map((t=>`relationships/${e.id}/${t.name}`)).toArray()))),yield*z(this._feature.attributes.keys(),e.toArray(),t)}*values(){yield*I(this.keys(),(e=>this.get(e)))}[(Symbol.toStringTag,Symbol.iterator)](){return this.entries()}toJSON(){return Array.from(this.entries())}on(e,t){if(d("callback",t).isNotMissing(),!this._numObservers){const e=new Map,t=new Set,s=()=>{t.forEach((e=>e.remove())),t.clear()},i=()=>{const t={added:Array.from(this.entries()).filter((t=>t[1]!==e.get(t[0]))),removed:Array.from(e.entries()).filter((e=>!this.has(e[0])||e[1]!==this.get(e[0]))),target:this};(t.added.length||t.removed.length)&&(this.emit("change",t),r())},r=()=>{e.clear(),s(),A(this.keys(),(s=>{const r=this._getFieldExtension(s);let a="{0}";if(r){const e=r.watch("format",(()=>{i()}));t.add(e),r.format&&(a=r.format)}e.set(s,this._formatAttribute(s,a))}))};r();const a=this._feature.attributes.on("change",(()=>{i()})),o=this._feature.schema.fieldExtensions.on("change",(()=>{i()})),n=this._feature.settings.formatSettings.watch(["numberFormat","dateFormat","locale"],(()=>{i()})),h=this._feature.expressionFieldValues.on("change",(()=>{i()})),l=this._feature.schema.fields.on("change",(e=>{(e.added?.some((e=>null!==e.name.match(w)))||e.removed?.some((e=>null!==e.name.match(w))))&&i()})),p=this._feature.settings.watch("popupTemplate",(()=>{i()}));this._onAllObserversRemoved=()=>{h.remove(),a.remove(),o.remove(),l.remove(),n.remove(),p.remove(),e.clear(),s()}}const s=super.on("change",t);return this._numObservers++,{remove:()=>{s.remove(),this._numObservers--,this._numObservers||this._onAllObserversRemoved()}}}watch(e,t){if("size"===e){const e=this._feature.attributes.watch("size",((e,s)=>{t(e+this._feature.schema.fields._expressionFieldsLength,s+this._feature.schema.fields._expressionFieldsLength,"size",this)})),s=this._feature.schema.fields.watch("_expressionFieldsLength",((e,s)=>{t(e+this._feature.attributes.size,s+this._feature.attributes.size,"size",this)}));return{remove:()=>{e.remove(),s.remove()}}}return super.watch(e,t)}_getFieldExtension(e){const t=this._feature.schema.findFieldByName(e);if(t)return this._feature.schema.fieldExtensions.forField(t)}_getFieldExtensionFormat(e){const t=this._getFieldExtension(e);return t?t.format:"{0}"}_formatAttribute(e,t){const s=e.match(w),i=e.match(F);if(s)return q(this._feature,"expression",s[1],{format:t});if(i){const[,e,s]=i;return q(this._feature,e,s,{format:t})}return q(this._feature,void 0,e,{format:t})}}const L=/\{(?:relationships[\\/]([\w-]*)[\\/])?(?:(expression)[\\/])?([_a-zA-ZÀ-ÖØ-öø-ÿ][._a-zA-ZÀ-ÖØ-öø-ÿ0-9]*)(?::([^}]*))?\}/g,K=/\{relationships\/([\w-]*)[\\/]([^}]*)\}/g,H=/{{/g,J="\0MAGIC\0",Z=new RegExp(J,"g"),Q="#INVALID";class B extends p{constructor(e){super(e.settings.hyperlinkTemplates,(e=>this._getHyperlink(e))),this._feature=e}_getHyperlink(e){return this._hyperlinks=this._hyperlinks||new WeakMap,this._hyperlinks.has(e)||this._hyperlinks.set(e,new W(this._feature,e)),this._hyperlinks.get(e)}}let W=class extends a{get url(){return this._template.url?this._feature.format(this._template.url):this._template.url}set url(e){throw new o(U)}get text(){return this._template.text?this._feature.format(this._template.text):this._template.text}set text(e){throw new o(U)}get iconUrl(){return this._template.iconUrl?this._feature.format(this._template.iconUrl):this._template.iconUrl}set iconUrl(e){throw new o(U)}get target(){return this._template.target?this._feature.format(this._template.target):this._template.target}set target(e){throw new o(U)}get tooltip(){return this._template.tooltip?this._feature.format(this._template.tooltip):this._template.tooltip}set tooltip(e){throw new o(U)}constructor(e,t){super(t.toJSON()),this._feature=e,this._template=t}_watchProperty(e,t,s,i){const r=super._watchProperty(e,t,s,i),a=this._template.watch(e,(()=>{this.notifyChange(e)})),o=this._feature.presentableAttributes.on("change",(()=>{this.notifyChange(e)})),n=this._feature.relatedFeatures.on("change",(()=>{this.notifyChange(e)}));return{remove:()=>{r.remove(),a.remove(),o.remove(),n.remove()}}}_getSerializableProperties(){return{}}};function q(e,t,s,i={format:"{0}"}){if("expression"!==t){if(t){const r=E(e.relatedFeatures.keys(),(e=>e.id===t));if(!r)return P.debug("Could not resolve related field '{0}/{1}",t,s),Q;const a=Array.from(e.relatedFeatures.get(r));return"many-to-one"===r.cardinality||"one-to-one"===r.cardinality?a.length<1?(P.debug("Could not resolve related field '{0}/{1}",t,s),Q):X(a[0],s,i):a.map((e=>X(e,s,i))).filter((e=>""!==e)).join(",")}return X(e,s,i)}if(!e.settings.popupTemplate?.expressionInfos?.find((e=>e.name===s)))return P.debug("Could not find expression '{0}'.",s),Q;try{const t=e.expressionFieldValues.get(s)??i.defaultExpressionValue??"",r=e.schema.findFieldByName(`expression/${s}`);let a=i;if(r){const t=e.schema.fieldExtensions.forField(r);a=te(e,s,ee(t.formatSettings),a)}return Y(e,t,a)}catch(e){if(e instanceof Error)return P.error({message:"Error evaluating expression '{0}': {1}.",error:e},s,e.message),Q;throw e}}function X(e,t,s){let i=e.attributes.get(t);if(null==i)return"";const r=e.schema.findFieldByName(t);let a={format:"{0}"};const o=e.type?.domains?.[r?.name??t];if(R(t,e.schema.typeIdField))i=e.type?e.type.name:i;else if(b(o)){const e=o.codedValues.find((e=>`${e.code}`==`${i.toString()}`));i=e?e.name:i}else if(r)if(b(r.domain)){const e=r.domain.codedValues.find((e=>`${e.code}`==`${i.toString()}`));e&&(i=e.name)}else{switch(r.type){case"integer":case"small-integer":case"single":case"double":i=j(i);break;case"date":i=y({timeZone:e.schema.timeZone},i);break;default:i=`${i.toString()}`}const t=e.schema.fieldExtensions.forField(r);t&&(a=ee(t.formatSettings))}return Y(e,i,te(e,t,a,s))}function Y(e,t,s){let i=s;if("number"==typeof t||t instanceof Date){i={...ee(e.settings.formatSettings),...s}}return"{0}"===i.format&&"string"==typeof t?t:C(i,t)}function ee(e){return{format:"{0}",dateFormat:e.dateFormat,numberFormat:e.numberFormat,currency:e.currency,fractionalDigits:e.fractionalDigits,locale:e.locale,timeZone:e.timeZone}}function te(e,t,s,i){const{popupTemplate:r}=e.settings,a=r?.fieldInfos?r.fieldInfos.find((e=>e.fieldName===t)):void 0,o=a?a.format:void 0;let n;return o&&(n={format:"{0}",numberFormat:o.digitSeparator?T.NUMBER:T.FIXED_POINT,dateFormat:_(o.dateFormat),fractionalDigits:o.places}),{...n,...s,...i}}W=e([h],W);export async function resolveRelatedFeatures(e){const t=f(e,(e=>e.source));await Promise.all(m([...t.keys()].map((e=>e.relationships.toArray()))).map((e=>(async e=>{[...(await e.getAllRelatedFeatures(t.get(e.source))).entries()].forEach((([t,s])=>{t.relatedFeatures.set(e,s)}))})(e))))}
|
|
1
|
+
import{__decorate as e}from"tslib";import t from"@arcgis/core/Graphic";import s from"@arcgis/core/core/Collection";import{fromJSON as i}from"@arcgis/core/geometry/support/jsonUtils";import{EntityBase as r}from"../Entity.js";import{Hyperlink as a}from"../Hyperlink.js";import{InvalidOperationError as o}from"../InvalidOperationError.js";import{ItemType as n}from"../ItemType.js";import{serializable as h}from"../support/Serializable.js";import{CaseInsensitiveObservableMap as l}from"../utilities/CaseInsensitiveObservableMap.js";import{MapTransformCollection as p}from"../utilities/MapTransformCollection.js";import{ObservableMap as u}from"../utilities/ObservableMap.js";import{ReadOnlyMap as c}from"../utilities/ReadOnlyMap.js";import{flatten as m,groupBy as f}from"../utilities/array.js";import{checkArg as d}from"../utilities/checkArg.js";import{compare as g}from"../utilities/collection.js";import{parse as y,esriFormatToGeocortexFormat as _}from"../utilities/date.js";import{isCodedValueDomain as b,isGeometry as x}from"../utilities/esri.js";import{fieldWithArcadeXRegex as w,fieldWithRelationshipRegex as F}from"../utilities/field.js";import{some as v,map as I,concat as z,forEach as A,find as E}from"../utilities/iterable.js";import{getLogger as S}from"../utilities/log.js";import{parse as j,NumberFormat as T}from"../utilities/number.js";import{map as k}from"../utilities/promise.js";import{caseInsensitiveEquals as R}from"../utilities/string.js";import{format as C}from"../utilities/string.js";import{onCollectionPropertyChange as M}from"../utilities/watch.js";import{FeatureSettings as O}from"./FeatureSettings.js";import{Schema as N}from"./Schema.js";const P=S("geocortex.api.data.Feature");export const SCORE_FIELD="_score";export const SCORE_FIELD_ORIGINAL="_score_original";let V=class extends r{get geometry(){return this._geometry}set geometry(e){this.notifyChange("geometryType"),this._geometry=x(e)||!e?e:i(e),this.schema.spatialReference=this._geometry?.spatialReference}get geometryType(){return this.geometry?this.geometry.type:void 0}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.schema.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0),this.notifyChange("attachmentsInitialized"),this.notifyChange("relatedFeaturesInitialized")}get primaryKey(){const e=this.attributes.get(this.schema.primaryKeyField);return null!=e?`${e}`:void 0}get hasGlobalId(){return!!this.schema.fields.find((e=>"global-id"===e.type))}get globalId(){const e=this.schema.fields.find((e=>"global-id"===e.type));return e?this.attributes.get(e.name):void 0}set globalId(e){const t=this.schema.fields.find((e=>"global-id"===e.type));if(!t)throw new o("Cannot set global ID on feature -- no global ID field.");this.attributes.set(t.name,e)}get presentableAttributes(){return this._presentableAttributes=this._presentableAttributes||new G(this),this._presentableAttributes}get title(){return this.format(this._title||"")}get description(){return this.format(this._description)}get hyperlinks(){return this._hyperlinks||(this._hyperlinks=new B(this))}get relatedFeatures(){return this._relatedFeatures}get type(){if(this.schema.typeIdField&&this.attributes.has(this.schema.typeIdField)){const e=this.attributes.get(this.schema.typeIdField);return this.schema.types.find((t=>t.id===e))}}get attachmentsInitialized(){return!this.source||this._attachmentsInitialized}get relatedFeaturesInitialized(){return!this.source||this.source.relationships.every((e=>this._initializedRelationships.has(e)))}get expressionsInitialized(){return!this.settings.popupTemplate?.expressionInfos?.length||this._expressionsInitialized}get _hydrationStatus(){return this._featureHydrationStatus?this._featureHydrationStatus:this.source?.capabilities?.supportsQuery&&1===this.attributes.size&&void 0!==this.primaryKey?"dehydrated":"hydrated"}set _hydrationStatus(e){this._featureHydrationStatus=e}get _key(){return`${this.source?.id}//${this.primaryKey??this.globalId??this.id}`}get _title(){let e;return this.settings.popupTemplate&&(e="function"==typeof this.settings.popupTemplate.title?this.settings.popupTemplate.title():this.settings.popupTemplate.title),e||this.schema.displayField&&this.presentableAttributes.get(this.schema.displayField)||""}get _description(){if(this.settings.popupTemplate?.content){if("string"==typeof this.settings.popupTemplate.content)return this.settings.popupTemplate.content;if(Array.isArray(this.settings.popupTemplate.content)){const e=this.settings.popupTemplate.content.find((e=>"text"===e.type));if(e)return e.text}}return""}constructor(e){super(e),this._itemType=n.FEATURE,this._expressionFieldValues=new u,this._expressionValuesUpdatePending=!1,this._attachmentsInitialized=!1,this._expressionsInitialized=!1,this._initializedRelationships=new WeakSet,this.settings=new O,this.settings._setFeature(this),this.schema=new N,this.schema._featureSettings=this.settings,this.attachments=new s,this.attributes=new l,this._relatedFeatures=new u,this.expressionFieldValues=new $(this._expressionFieldValues,this),M(this,"source.relationships",(()=>{this.notifyChange("relatedFeaturesInitialized")}),!0),this.settings.watch("popupTemplate",((e,t)=>{e!==t&&(this._expressionsInitialized=!1,this.notifyChange("expressionsInitialized"))}),!0)}format(e,...t){let s="string"==typeof e?{format:e}:e;d("options",s).isNotMissing();const{format:i}=s;d("format",i).isNotMissing();let r=s.format.replace(H,J);return r=r.replace(L,((e,t,i,r,a)=>q(this,t||i,r,{...s,format:a?`{0:${a}}`:"{0}"}))),r=r.replace(Z,"{{"),s={...s},s.format=r,C(s,...t)}clearExpressionInfos(){this._expressionFieldValues.clear()}toGraphic(){return toGraphic(this)}async fetchExpressionInfos(e=!1){const{expressionInfos:t}=this.settings.popupTemplate??{};if(!t)return;const{runAsyncArcadeExpression:s}=await import("../utilities/arcade.js");if(await Promise.all(t.map((async e=>{try{const t=this.source?.layer??this.source?.sublayer;let i=this.source?.mapExtension;if(!i){const e=this.source?.layerExtension;i=e?.mapExtension}this._expressionFieldValues.set(e.name,await s(e.expression,{layer:t,map:i?.map,feature:this,spatialReference:this.schema.spatialReference}))}catch(t){t instanceof Error&&P.error({message:"Error evaluating expression '{0}': {1}.",error:t},e.name,t.message),this._expressionFieldValues.set(e.name,Q)}}))),e)return this.attributes.on("change",(async e=>{this._expressionValuesUpdatePending||(this._expressionValuesUpdatePending=!0,setTimeout((async()=>{this._expressionValuesUpdatePending=!1,await this.fetchExpressionInfos()}),0))}));this._expressionsInitialized=!0,this.notifyChange("expressionsInitialized")}async fetchRelatedFeatures(e,t){if(!this.source)return;let s=[];if(e){const t=new Set(Array.isArray(e)?e:[e]);for(const e of t){const t="string"==typeof e?this.source.relationships.find((t=>t.id===e)):e;if(!t||!this.source.relationships.includes(t))throw new o("Relationship not found in feature source.");s.push(t)}}else s=this.source.relationships.toArray();const i=await k(s,(async e=>[e,await(async()=>{const s=await e.getRelatedFeatures(this,t);return this._initializedRelationships.add(e),s})()]));for(const e of i)this._relatedFeatures.set(e[0],e[1]);this.notifyChange("relatedFeaturesInitialized")}async fetchAttachments(){if(this.source){const e=await this.source.getAttachments(this);g(this.attachments,e,{equals:(e,t)=>e.id===t.id,onMissing:(e,t)=>this.attachments.remove(e),onNew:(e,t)=>{this.attachments.add(e)},onMatch:(e,t,s,i)=>{this.attachments.splice(s,1,t)}}),this._attachmentsInitialized=!0,this.notifyChange("attachmentsInitialized")}}async addAttachment(e){return this.source?.addAttachment(this,e)}async deleteAttachments(e){return this.source?.deleteAttachments(this,e)}_getSerializableProperties(){return{...super._getSerializableProperties(),attributes:{serializeModes:["project"],serialize:e=>{const t={};if("project"===e&&this.primaryKey&&(this.source?.capabilities).supportsQuery)t[this.schema.primaryKeyField]=this.primaryKey;else for(const[e,s]of this.attributes.entries())t[e]=s;return t},deserialize:e=>{if(this.attributes.clear(),e instanceof Map)e.forEach(((e,t)=>{this.attributes.set(t,e)}));else for(const[t,s]of Object.entries(e))this.attributes.set(t,s)}},geometry:{serializeModes:["project"],serialize:e=>"project"===e&&(this.source?.capabilities).supportsQuery?this.getDefault("geometry"):this.geometry?.toJSON(),deserialize:e=>{this.geometry=e}},settings:{serializeModes:["project"],serialize:e=>"project"===e&&(this.source?.capabilities).supportsQuery?this.getDefault("settings"):this.settings.toJSON(e)},schema:{serializeModes:["project"],serialize:e=>"project"===e&&(this.source?.capabilities).supportsQuery?this.getDefault("schema"):this.schema.toJSON(e)},source:["project"]}}_watchProperty(e,t,s,i){if("title"===e||"description"===e){const r=super._watchProperty(e,t,s,i),a="title"===e?"settings.popupTemplate.title":"settings.popupTemplate.content",o=this.watch(a,(()=>{this.notifyChange(e)})),n=this.presentableAttributes.on("change",(()=>{this.notifyChange(e)}));return{remove(){r.remove(),o.remove(),n.remove()}}}return super._watchProperty(e,t,s,i)}async _onInitialize(){const e=this._findRelationshipIds(this._title,this._description),t=this.source?this.source.relationships.map((e=>e.id)).toArray():[],s=[];for(const i of e)t.includes(i)?s.push(this.fetchRelatedFeatures(i)):P.error("Could not find relationship '{0}' referenced in feature title or description.",i);await Promise.all(s)}_findRelationshipIds(...e){const t=[];for(const s of e){let e;const i=s.replace(H,J);for(;e=K.exec(i),null!==e;){const s=e[0];t.includes(s)||t.push(e[1])}}return t}};V=e([h],V);export{V as Feature};export function toFeature(e,t){const s=new V(t);if(e.attributes)for(const t of Object.keys(e.attributes))s.attributes.set(t,e.attributes[t]);return s.geometry=e.geometry,e.popupTemplate&&(s.settings.popupTemplate=e.popupTemplate),s}export function toGraphic(e){const s=new t;s.attributes={};for(const t of e.attributes.keys())s.attributes[t]=e.attributes.get(t);return e.source?.layer&&(s.layer=e.source?.layer),s.geometry=e.geometry,e.settings.popupTemplate&&(s.popupTemplate=e.settings.popupTemplate),s}const D="Presentable attributes are read-only.",U="Feature hyperlinks are read-only. Modify the feature's hyperlink templates instead.";class $ extends c{constructor(e,t){super(e),this._feature=t}get(e){if(!super.has(e)){const{spatialReference:t}=this._feature.schema,s=this._feature.settings.popupTemplate?.expressionInfos?.find((t=>t.name===e));if(!s)return;(async()=>{const{isArcadeScriptAsync:i,runAsyncArcadeExpression:r,arcadeScriptUsesGeometry:a,runArcadeExpression:o}=await import("../utilities/arcade.js");try{if(i(s.expression,t)){const i=this._feature.source?.layer??this._feature.source?.sublayer;let a=this._feature.source?.mapExtension;if(!a){const e=this._feature.source?.layerExtension;a=e?.mapExtension}this._originalMap.set(e,await r(s.expression,{feature:this._feature,layer:i,map:a?.map,spatialReference:t}))}else{if(a(s.expression,t)){const{enableGeometrySupport:e}=await import("@arcgis/core/arcade/arcade");await e()}this._originalMap.set(e,o(s.expression,{feature:this._feature,spatialReference:t}))}}catch(t){t instanceof Error&&P.error({message:"Error evaluating expression '{0}': {1}.",error:t},e,t.message),this._originalMap.set(e,Q)}})()}return super.get(e)}}class G extends c{get size(){return this._feature.attributes.size+this._feature.schema.fields._expressionFieldsLength}constructor(e){super(new l),this._feature=e}clear(){throw new o(D)}delete(e){throw new o(D)}forEach(e,t){d("callback",e).isNotMissing();for(const s of this.keys())e.call(t,this.get(s),s,this)}get(e){const t=this._getFieldExtensionFormat(e);return this._formatAttribute(e,t)}has(e){return v(this.keys(),(t=>R(t,e)))}set(...e){throw new o(D)}*entries(){yield*I(this.keys(),(e=>[e,this.get(e)]))}*keys(){const e=this._feature.schema.fields.expressionFields.map((e=>e.name)),t=[];this._feature.source?.relationships&&this._feature.source.relationships.filter((e=>"one-to-one"===e.cardinality||"many-to-one"===e.cardinality)).forEach((e=>t.push(...e.relatedSource.schema.fields.map((t=>`relationships/${e.id}/${t.name}`)).toArray()))),yield*z(this._feature.attributes.keys(),e.toArray(),t)}*values(){yield*I(this.keys(),(e=>this.get(e)))}[(Symbol.toStringTag,Symbol.iterator)](){return this.entries()}toJSON(){return Array.from(this.entries())}on(e,t){if(d("callback",t).isNotMissing(),!this._numObservers){const e=new Map,t=new Set,s=()=>{t.forEach((e=>e.remove())),t.clear()},i=()=>{const t={added:Array.from(this.entries()).filter((t=>t[1]!==e.get(t[0]))),removed:Array.from(e.entries()).filter((e=>!this.has(e[0])||e[1]!==this.get(e[0]))),target:this};(t.added.length||t.removed.length)&&(this.emit("change",t),r())},r=()=>{e.clear(),s(),A(this.keys(),(s=>{const r=this._getFieldExtension(s);let a="{0}";if(r){const e=r.watch("format",(()=>{i()}));t.add(e),r.format&&(a=r.format)}e.set(s,this._formatAttribute(s,a))}))};r();const a=this._feature.attributes.on("change",(()=>{i()})),o=this._feature.schema.fieldExtensions.on("change",(()=>{i()})),n=this._feature.settings.formatSettings.watch(["numberFormat","dateFormat","locale"],(()=>{i()})),h=this._feature.expressionFieldValues.on("change",(()=>{i()})),l=this._feature.schema.fields.on("change",(e=>{(e.added?.some((e=>null!==e.name.match(w)))||e.removed?.some((e=>null!==e.name.match(w))))&&i()})),p=this._feature.settings.watch("popupTemplate",(()=>{i()}));this._onAllObserversRemoved=()=>{h.remove(),a.remove(),o.remove(),l.remove(),n.remove(),p.remove(),e.clear(),s()}}const s=super.on("change",t);return this._numObservers++,{remove:()=>{s.remove(),this._numObservers--,this._numObservers||this._onAllObserversRemoved()}}}watch(e,t){if("size"===e){const e=this._feature.attributes.watch("size",((e,s)=>{t(e+this._feature.schema.fields._expressionFieldsLength,s+this._feature.schema.fields._expressionFieldsLength,"size",this)})),s=this._feature.schema.fields.watch("_expressionFieldsLength",((e,s)=>{t(e+this._feature.attributes.size,s+this._feature.attributes.size,"size",this)}));return{remove:()=>{e.remove(),s.remove()}}}return super.watch(e,t)}_getFieldExtension(e){const t=this._feature.schema.findFieldByName(e);if(t)return this._feature.schema.fieldExtensions.forField(t)}_getFieldExtensionFormat(e){const t=this._getFieldExtension(e);return t?t.format:"{0}"}_formatAttribute(e,t){const s=e.match(w),i=e.match(F);if(s)return q(this._feature,"expression",s[1],{format:t});if(i){const[,e,s]=i;return q(this._feature,e,s,{format:t})}return q(this._feature,void 0,e,{format:t})}}const L=/\{(?:relationships[\\/]([\w-]*)[\\/])?(?:(expression)[\\/])?([_a-zA-ZÀ-ÖØ-öø-ÿ][._a-zA-ZÀ-ÖØ-öø-ÿ0-9]*)(?::([^}]*))?\}/g,K=/\{relationships\/([\w-]*)[\\/]([^}]*)\}/g,H=/{{/g,J="\0MAGIC\0",Z=new RegExp(J,"g"),Q="#INVALID";class B extends p{constructor(e){super(e.settings.hyperlinkTemplates,(e=>this._getHyperlink(e))),this._feature=e}_getHyperlink(e){return this._hyperlinks=this._hyperlinks||new WeakMap,this._hyperlinks.has(e)||this._hyperlinks.set(e,new W(this._feature,e)),this._hyperlinks.get(e)}}let W=class extends a{get url(){return this._template.url?this._feature.format(this._template.url):this._template.url}set url(e){throw new o(U)}get text(){return this._template.text?this._feature.format(this._template.text):this._template.text}set text(e){throw new o(U)}get iconUrl(){return this._template.iconUrl?this._feature.format(this._template.iconUrl):this._template.iconUrl}set iconUrl(e){throw new o(U)}get target(){return this._template.target?this._feature.format(this._template.target):this._template.target}set target(e){throw new o(U)}get tooltip(){return this._template.tooltip?this._feature.format(this._template.tooltip):this._template.tooltip}set tooltip(e){throw new o(U)}constructor(e,t){super(t.toJSON()),this._feature=e,this._template=t}_watchProperty(e,t,s,i){const r=super._watchProperty(e,t,s,i),a=this._template.watch(e,(()=>{this.notifyChange(e)})),o=this._feature.presentableAttributes.on("change",(()=>{this.notifyChange(e)})),n=this._feature.relatedFeatures.on("change",(()=>{this.notifyChange(e)}));return{remove:()=>{r.remove(),a.remove(),o.remove(),n.remove()}}}_getSerializableProperties(){return{}}};function q(e,t,s,i={format:"{0}"}){if("expression"!==t){if(t){const r=E(e.relatedFeatures.keys(),(e=>e.id===t));if(!r)return P.debug("Could not resolve related field '{0}/{1}",t,s),Q;const a=Array.from(e.relatedFeatures.get(r));return"many-to-one"===r.cardinality||"one-to-one"===r.cardinality?a.length<1?(P.debug("Could not resolve related field '{0}/{1}",t,s),Q):X(a[0],s,i):a.map((e=>X(e,s,i))).filter((e=>""!==e)).join(",")}return X(e,s,i)}if(!e.settings.popupTemplate?.expressionInfos?.find((e=>R(e.name,s))))return P.debug("Could not find expression '{0}'.",s),Q;try{const t=e.expressionFieldValues.get(s)??i.defaultExpressionValue??"",r=e.schema.findFieldByName(`expression/${s}`);let a=i;if(r){const t=e.schema.fieldExtensions.forField(r);a=te(e,s,ee(t.formatSettings),a)}return Y(e,t,a)}catch(e){if(e instanceof Error)return P.error({message:"Error evaluating expression '{0}': {1}.",error:e},s,e.message),Q;throw e}}function X(e,t,s){let i=e.attributes.get(t);if(null==i)return"";const r=e.schema.findFieldByName(t);let a={format:"{0}"};const o=e.type?.domains?.[r?.name??t];if(R(t,e.schema.typeIdField))i=e.type?e.type.name:i;else if(b(o)){const e=o.codedValues.find((e=>`${e.code}`==`${i.toString()}`));i=e?e.name:i}else if(r)if(b(r.domain)){const e=r.domain.codedValues.find((e=>`${e.code}`==`${i.toString()}`));e&&(i=e.name)}else{switch(r.type){case"integer":case"small-integer":case"single":case"double":i=j(i);break;case"date":i=y({timeZone:e.schema.timeZone},i);break;default:i=`${i.toString()}`}const t=e.schema.fieldExtensions.forField(r);t&&(a=ee(t.formatSettings))}return Y(e,i,te(e,t,a,s))}function Y(e,t,s){let i=s;if("number"==typeof t||t instanceof Date){i={...ee(e.settings.formatSettings),...s}}return"{0}"===i.format&&"string"==typeof t?t:C(i,t)}function ee(e){return{format:"{0}",dateFormat:e.dateFormat,numberFormat:e.numberFormat,currency:e.currency,fractionalDigits:e.fractionalDigits,locale:e.locale,timeZone:e.timeZone}}function te(e,t,s,i){const{popupTemplate:r}=e.settings,a=r?.fieldInfos?r.fieldInfos.find((e=>R(e.fieldName,t))):void 0,o=a?a.format:void 0;let n;return o&&(n={format:"{0}",numberFormat:o.digitSeparator?T.NUMBER:T.FIXED_POINT,dateFormat:_(o.dateFormat),fractionalDigits:o.places}),{...n,...s,...i}}W=e([h],W);export async function resolveRelatedFeatures(e){const t=f(e,(e=>e.source));await Promise.all(m([...t.keys()].map((e=>e.relationships.toArray()))).map((e=>(async e=>{[...(await e.getAllRelatedFeatures(t.get(e.source))).entries()].forEach((([t,s])=>{t.relatedFeatures.set(e,s)}))})(e))))}
|
package/data/FeatureSettings.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__decorate as t}from"tslib";import e from"@arcgis/core/PopupTemplate";import{Hyperlink as i}from"../Hyperlink.js";import{isPopupContentExtension as n}from"../ItemType.js";import{ArrayWrappedCollection as o}from"../mapping/support/ArrayWrappedCollection.js";import{FormatSettings as s}from"../support/FormatSettings.js";import{InitializableCollectionProxy as r}from"../support/InitializableCollectionProxy.js";import{filterJSONProperties as p,isDefault as a,serializable as u,shouldExcludeDefaults as l}from"../support/Serializable.js";import{Settings as h}from"../support/Settings.js";import{compare as f}from"../utilities/array.js";import{checkArg as m}from"../utilities/checkArg.js";import{getAllFieldInfos as d,getAllReferencedFieldNames as c,isPopupTemplate as _}from"../utilities/esri.js";import{fieldWithArcadeXRegex as g,fieldWithRelationshipRegex as S}from"../utilities/field.js";import{isQueryBasedRelationship as C}from"../utilities/relationships.js";import{
|
|
1
|
+
import{__decorate as t}from"tslib";import e from"@arcgis/core/PopupTemplate";import{Hyperlink as i}from"../Hyperlink.js";import{isPopupContentExtension as n}from"../ItemType.js";import{ArrayWrappedCollection as o}from"../mapping/support/ArrayWrappedCollection.js";import{FormatSettings as s}from"../support/FormatSettings.js";import{InitializableCollectionProxy as r}from"../support/InitializableCollectionProxy.js";import{filterJSONProperties as p,isDefault as a,serializable as u,shouldExcludeDefaults as l}from"../support/Serializable.js";import{Settings as h}from"../support/Settings.js";import{compare as f}from"../utilities/array.js";import{checkArg as m}from"../utilities/checkArg.js";import{getAllFieldInfos as d,getAllReferencedFieldNames as c,isPopupTemplate as _}from"../utilities/esri.js";import{fieldWithArcadeXRegex as g,fieldWithRelationshipRegex as S}from"../utilities/field.js";import{isQueryBasedRelationship as C}from"../utilities/relationships.js";import{caseInsensitiveEquals as y}from"../utilities/string.js";import{onCollectionPropertyChange as T}from"../utilities/watch.js";import{PopupContentExtension as x,_popupContentExtensionMap as z}from"./PopupContentExtension.js";let E=class extends h{get _popupContent(){return this._popupContentCollection}get hyperlinkTemplates(){return this._getCollectionSetting("hyperlinkTemplates")}get popupTemplate(){return this._getSetting("popupTemplate")}set popupTemplate(t){let i;i=t instanceof Object&&!_(t)?e.fromJSON(t):t;const n=this?._feature?.schema?.createPopupTemplate()??this?._featureSource?.schema?.createPopupTemplate();i&&n&&(i.content=i.content??n.content,i.fieldInfos=i.fieldInfos??n.fieldInfos),this._setSetting("popupTemplate",i),this._isDefaultPopupTemplate=!1}get formatSettings(){return this._getNestedSettings("formatSettings",(()=>new s))}get returnGeometry(){return this._getSetting("returnGeometry",!0)}set returnGeometry(t){this._setSetting("returnGeometry",t)}get outFields(){return this._getSetting("outFields",this._defaultOutFields)}set outFields(t){this._setSetting("outFields",t)}get outSpatialReference(){return this._getSetting("outSpatialReference")}set outSpatialReference(t){this._setSetting("outSpatialReference",t)}get maxAllowableOffset(){return this._getSetting("maxAllowableOffset")}set maxAllowableOffset(t){this._setSetting("maxAllowableOffset",t)}get zoomScale(){return this._getSetting("zoomScale")}set zoomScale(t){this._setSetting("zoomScale",t)}get zoomFactor(){const t=this._feature?this._feature.schema:this._featureSource?.schema,e=t&&"point"===t.geometryType?void 0:1.5;return this._getSetting("zoomFactor",e)}set zoomFactor(t){this._setSetting("zoomFactor",t)}get featureSource(){return this._featureSource}get feature(){return this._feature}constructor(t){super(t),this._isDefaultPopupTemplate=!1,this._popupContentCollection=this._createPopupContentCollection(),this.popupContentExtensions=new v(this)}get _defaultOutFields(){const t=d(this.popupTemplate),e=this.featureSource?.schema?.primaryKeyField;if(t&&e){const i=new Set;i.add(e);const n=this.featureSource.schema.fields.toArray().map((t=>t.name)),o=new Set([...c(this.popupTemplate),...this.hyperlinkTemplates.toArray().flatMap((t=>t.getReferencedFields()))]),s=t.filter((t=>t.visible||t.isEditable&&this.featureSource.capabilities.supportsEditing)).map((t=>t.fieldName)).concat(...o).filter((t=>n.some((e=>y(e,t)))));return this._featureSource.relationships.forEach((t=>{C(t)&&s.push(t.keyField)})),s.filter((t=>!(t.match(g)||t.match(S)))).forEach((t=>i.add(t))),Array.from(i.values())}return["*"]}_setFeatureSource(t){this._featureSource=t,this.notifyChange("featureSource")}_setFeature(t){this._feature=t,this.notifyChange("feature")}toJSON(t="all"){const e=p(this._getSerializableProperties(),this,t)||{},i=e.popupContentExtensions?.filter((t=>{const e=this.parent;return!e?.popupContentExtensions?.some((e=>e.id===t.id))}));if(e)for(const t of Object.keys(e))this.isModified(t)||delete e[t];if(i?.length&&(e.popupContentExtensions=i),!l(t)||!a(e))return e}_createPopupContentCollection(){return new o({parent:this,targetProperty:"popupTemplate",arrayProperty:"content"})}_getSerializableProperties(){return{hyperlinkTemplates:{serializeModes:["initial"],deserialize:t=>{t.forEach((t=>{this.hyperlinkTemplates.find((e=>this._hyperlinksAreEquivalent(e,t)))||this.hyperlinkTemplates.add(t instanceof i?t:new i(t))})),this.hyperlinkTemplates.toArray().forEach((e=>{const i=this.hyperlinkTemplates.indexOf(e),n=t.findIndex((t=>this._hyperlinksAreEquivalent(t,e)));n<0?this.hyperlinkTemplates.removeAt(i):n!==i&&this.hyperlinkTemplates.reorder(e,n)}))}},popupTemplate:{serialize:!1},formatSettings:"initial",outFields:{serializeModes:["initial"],serialize:()=>this.isModified("outFields")?this.outFields:void 0},returnGeometry:{serializeModes:["initial"],default:!0},outSpatialReference:"initial",maxAllowableOffset:"initial",zoomScale:"initial",zoomFactor:{serializeModes:["initial"],isDefault:t=>{const e=this._feature?this._feature.schema:this._featureSource?.schema;return t===(e&&"point"===e.geometryType?void 0:1.5)}},popupContentExtensions:{serializeModes:["initial"],serialize:t=>this.popupContentExtensions.map((e=>e.toJSON(t))).filter((t=>!(t&&2===Object.keys(t).length&&t.id&&t.content))).toArray(),deserialize:t=>{t&&f(this.popupContentExtensions,t,{onNew:(t,e)=>{this.popupContentExtensions.add(n(t)?t:new x(t),e)},onMatch:(t,e,i,o)=>{n(e)||t.assignProperties(e),i!==o&&this.popupContentExtensions.reorder(t,o)},onMissing:t=>{this.popupContentExtensions.remove(t)},equals:(t,e)=>n(e)?e===t||e.id===t.id:!(!e?.content||!x.matchesRef(this.popupContentExtensions.toArray(),this.popupContentExtensions.indexOf(t),e.content))||t.id===e.id})}}}}_hyperlinksAreEquivalent(t,e){if(t===e)return!0;const i=t=>t||"";return i(t.text)===i(e.text)&&i(t.url)===i(e.url)&&i(t.iconUrl)===i(e.iconUrl)&&i(t.target)===i(e.target)&&i(t.tooltip)===i(e.tooltip)}};E=t([u],E);export{E as FeatureSettings};class v extends r{get _collection(){return this._featureSettings._popupContent.map((t=>this._forContent(t))).concat(Array.from(this._uninitializedPopupContentExtensions))}get _popupTemplateIsInherited(){return this._featureSettings.parent&&this._featureSettings.popupTemplate===this._featureSettings.parent.popupTemplate}constructor(t){super(),this._uninitializedPopupContentExtensions=new Set,this._featureSettings=t,T(this._featureSettings,"_popupContent",(t=>{const e={added:(t.added||[]).map((t=>this._forContent(t))),moved:(t.moved||[]).map((t=>this._forContent(t))),removed:(t.removed||[]).map((t=>this._forContent(t))),target:this};this.emit("change",e)})),t.watch("_popupContent.length",(()=>this.notifyChange("length")))}forContent(t){if(m("content",t).isNotMissing(),this._featureSettings._popupContent.includes(t))return this._forContent(t)}add(t,i){if(m("contentX",t).isNotMissing(),this._popupTemplateIsInherited&&(this._featureSettings.popupTemplate=new e({content:this._featureSettings._popupContent.toArray()})),t.featureSettings&&t.featureSettings.popupContentExtensions.remove(t),t._setFeatureSettings(this._featureSettings),t.content){const e=z.get(t.content);if(z.set(t.content,t),e&&e!==t&&this._onRemoved(e),this._featureSettings._popupContent.includes(t.content))if(void 0===i){const i={added:[t],moved:[],removed:e?[e]:[],target:this};this.emit("change",i)}else this._featureSettings._popupContent.reorder(t.content,i);else this._featureSettings._popupContent.add(t.content,i)}else{this._uninitializedPopupContentExtensions.add(t);const e={added:[t],moved:[],removed:[],target:this};this.emit("change",e)}return this._onAdded(t),this}removeAt(t){const i=this.getItemAt(t);if(void 0!==i){if(this._popupTemplateIsInherited&&(this._featureSettings.popupTemplate=new e({content:this._featureSettings._popupContent.toArray()})),this._uninitializedPopupContentExtensions.has(i)){this._uninitializedPopupContentExtensions.delete(i);const t={added:[],moved:[],removed:[i],target:this};this.emit("change",t)}else this._featureSettings._popupContent.remove(i.content);return this._onRemoved(i),i}}reorder(t,i){if(t&&this._featureSettings._popupContent.includes(t.content))return this._popupTemplateIsInherited&&(this._featureSettings.popupTemplate=new e({content:this._featureSettings._popupContent.toArray()})),this._featureSettings._popupContent.reorder(t.content,i),t}sort(t){return this._popupTemplateIsInherited&&(this._featureSettings.popupTemplate=new e({content:this._featureSettings._popupContent.toArray()})),this._featureSettings._popupContent.sort(((e,i)=>t(this._forContent(e),this._forContent(i)))),this}_itemIsInitialized(t){return super._itemIsInitialized(t)&&!!t.content}_onAdded(t){}_onRemoved(t){t.featureSettings===this._featureSettings&&t._setFeatureSettings(void 0)}_forContent(t){if(this._uninitializedPopupContentExtensions.size)for(const t of this._uninitializedPopupContentExtensions)t._resolveContent(),t.content&&(z.set(t.content,t),this._uninitializedPopupContentExtensions.delete(t));if(!z.has(t)){const e=new x({content:t});z.set(t,e),e._setFeatureSettings(this._featureSettings),this._onAdded(e)}return z.get(t)}}
|
package/data/FieldExtension.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e;import{__decorate as i}from"tslib";import t from"@arcgis/core/layers/support/Field";import{EntityBase as s}from"../Entity.js";import{InvalidOperationError as r}from"../InvalidOperationError.js";import{isFieldExtension as o,ItemType as f}from"../ItemType.js";import{FormatSettings as a}from"../support/FormatSettings.js";import{serializable as n}from"../support/Serializable.js";import{esriFormatToGeocortexFormat as d}from"../utilities/date.js";import{isField as l}from"../utilities/esri.js";import{fieldWithArcadeXRegex as h}from"../utilities/field.js";import{NumberFormat as m}from"../utilities/number.js";import{deepClone as _}from"../utilities/object.js";import{caseInsensitiveEquals as p}from"../utilities/string.js";export const _fieldExtensionMap=new WeakMap;let c=e=class extends s{get field(){return this._field}get schema(){return this._schema}get fieldInfo(){if(this._fieldInfo)return this._fieldInfo;if(!this.field?.name)return;const e=this._schema?._featureSettings?.popupTemplate,i=e?.fieldInfos||[];return this._fieldInfo=i.find((e=>e.fieldName
|
|
1
|
+
var e;import{__decorate as i}from"tslib";import t from"@arcgis/core/layers/support/Field";import{EntityBase as s}from"../Entity.js";import{InvalidOperationError as r}from"../InvalidOperationError.js";import{isFieldExtension as o,ItemType as f}from"../ItemType.js";import{FormatSettings as a}from"../support/FormatSettings.js";import{serializable as n}from"../support/Serializable.js";import{esriFormatToGeocortexFormat as d}from"../utilities/date.js";import{isField as l}from"../utilities/esri.js";import{fieldWithArcadeXRegex as h}from"../utilities/field.js";import{NumberFormat as m}from"../utilities/number.js";import{deepClone as _}from"../utilities/object.js";import{caseInsensitiveEquals as p}from"../utilities/string.js";export const _fieldExtensionMap=new WeakMap;let c=e=class extends s{get field(){return this._field}get schema(){return this._schema}get fieldInfo(){if(this._fieldInfo)return this._fieldInfo;if(!this.field?.name)return;const e=this._schema?._featureSettings?.popupTemplate,i=e?.fieldInfos||[];return this._fieldInfo=i.find((e=>p(e.fieldName,this.field.name))),this._fieldInfo}constructor(e){super(e),this.format="{0}",this.formatSettings=new g(this),this.searchable=!0,this._itemType=f.FIELD_EXTENSION;const{field:i}=e??{};l(i)?this._setField(i):"string"==typeof i?this._deferredFieldProperties={$ref:i}:i?i.$ref?this._deferredFieldProperties=i:this._setField(t.fromJSON(i)):this._setField(new t),this.watch("_schema.featureSource",(()=>this.notifyChange("fieldInfo"))),this.watch("_schema._featureSettings",(e=>{this.formatSettings.parent=e?e.formatSettings:void 0}),!0)}static matchesRef(e,i){return o(e)?p(e.field?.name??e._deferredFieldProperties?.$ref,i.$ref):p(e.name,i.$ref)}_setSchema(e){this._schema=e,this._resolveField(),this.notifyChange("schema"),this.notifyChange("fieldInfo")}_resolveField(){if(this._field||!this._deferredFieldProperties||!this._schema)return;const i=this._schema.fields.find((i=>e.matchesRef(i,this._deferredFieldProperties)));i&&(this._setField(i),this.assignProperties({field:this._deferredFieldProperties}),this._originalRef=this._deferredFieldProperties.$ref,delete this._deferredFieldProperties,_fieldExtensionMap.set(i,this))}_getSerializableProperties(){return{...super._getSerializableProperties(),field:{serializeModes:["initial"],serialize:()=>this.field?this._originalRef?{$ref:this._originalRef}:this._schema?.fields.includes(this._field)&&this.field.name?{$ref:this.field.name}:this.field.toJSON():this._deferredFieldProperties?_(this._deferredFieldProperties):void 0,deserialize:e=>{if(l(e)&&e!==this.field)throw new Error("Property 'field' is read-only.")}},searchable:{serializeModes:["initial"],isDefault:e=>e!==this._isArcadeExpressionField},format:{serializeModes:["initial"],default:"{0}"},formatSettings:"initial"}}async _onInitialize(){if(this._resolveField(),!this._field){const e=this._deferredFieldProperties.$ref;throw this._schema?new r(`Field not found with name: ${e}. Field does not exist.`):new r(`Field not found with name: ${e}. Field does not have a parent schema.`)}}_setField(e){this._field=e,this._isArcadeExpressionField&&(this.searchable=!1),this.notifyChange("field"),this.notifyChange("fieldInfo")}get _isArcadeExpressionField(){return!!this._field&&!!this._field.name&&!!this._field.name.match(h)}};c=e=i([n],c);export{c as FieldExtension};let g=class extends a{constructor(e,i){super(i),this.fieldExtension=e,e.watch("fieldInfo.format.places",(()=>this.notifyChange("fractionalDigits"))),e.watch("fieldInfo.format.digitSeparator",(()=>this.notifyChange("numberFormat"))),e.watch("fieldInfo.format.dateFormat",(()=>this.notifyChange("dateFormat")))}get fractionalDigits(){const e=this.fieldExtension.fieldInfo?.format?.places;return!this.isModified("fractionalDigits")&&this.useFieldInfo&&e?e:this._getSetting("fractionalDigits")}set fractionalDigits(e){this._setSetting("fractionalDigits",e)}get numberFormat(){const e=this.fieldExtension.fieldInfo?.format?.digitSeparator;return!this.isModified("numberFormat")&&this.useFieldInfo&&e?e?m.NUMBER:m.FIXED_POINT:this._getSetting("numberFormat")}set numberFormat(e){this._setSetting("numberFormat",e)}get dateFormat(){const e=this.fieldExtension.fieldInfo?.format?.dateFormat;return!this.isModified("dateFormat")&&this.useFieldInfo&&e?d(e):this._getSetting("dateFormat")}set dateFormat(e){this._setSetting("dateFormat",e)}};g=i([n],g);
|
package/data/Schema.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e;import{__decorate as t}from"tslib";import i from"@arcgis/core/PopupTemplate";import s from"@arcgis/core/core/Collection";import o from"@arcgis/core/layers/support/FeatureType";import n from"@arcgis/core/layers/support/Field";import l from"@arcgis/core/popup/FieldInfo";import{InvalidOperationError as r}from"../InvalidOperationError.js";import{isFieldExtension as d}from"../ItemType.js";import{jsonToGeometryType as a}from"../json/GeometryJson.js";import{InitializableCollectionProxy as h}from"../support/InitializableCollectionProxy.js";import{filterJSONProperties as p,isDefault as m,serializable as f,shouldExcludeDefaults as c}from"../support/Serializable.js";import{Settings as u}from"../support/Settings.js";import{CollectionProxy as _}from"../utilities/CollectionProxy.js";import{checkArg as g}from"../utilities/checkArg.js";import{compare as y}from"../utilities/collection.js";import{isValidTimeZone as F,ERR_TIME_ZONE_INVALID as b}from"../utilities/date.js";import{isFeatureType as x,isField as v}from"../utilities/esri.js";import{fieldWithArcadeXRegex as S,fieldWithRelationshipRegex as z}from"../utilities/field.js";import{caseInsensitiveEquals as I}from"../utilities/string.js";import{onCollectionPropertyChange as T}from"../utilities/watch.js";import{_fieldExtensionMap as w,FieldExtension as E}from"./FieldExtension.js";const N=new Map;N.set("objectid","oid"),N.set("oid","oid"),N.set("fid","oid"),N.set("shape","geometry"),N.set("shape__length","double"),N.set("shape_length","double"),N.set("shape__area","double"),N.set("shape_area","double"),N.set("area","double"),N.set("perimeter","double"),N.set("length","double"),N.set("fnode_","double"),N.set("tnode_","double"),N.set("lpoly_","double"),N.set("rpoly_","double"),N.set("cover_","integer"),N.set("cover_id","integer"),N.set("idtic","integer"),N.set("xtic","double"),N.set("ytic","double"),N.set("xmin","double"),N.set("ymin","double"),N.set("xmax","double"),N.set("ymax","double"),N.set("arc_","double"),N.set("subclass_","integer"),N.set("subclass_id","integer"),N.set("routelink","integer"),N.set("arclink","integer"),N.set("f_meas","double"),N.set("t_meas","double"),N.set("f_pos","double"),N.set("t_pos","double"),N.set("f_meas","double"),N.set("globalid","global-id"),N.set("guid","guid");export{S as fieldWithArcadeXRegex,z as fieldWithRelationshipRegex};const j=new WeakMap;let M=e=class extends u{get spatialReference(){return this._getSetting("spatialReference")}set spatialReference(e){this._setSetting("spatialReference",e)}get primaryKeyField(){const e=this._getSetting("primaryKeyField");if(!e){const e=this.fields.filter((e=>"oid"===e.type));if(1===e.length)return e.getItemAt(0).name}return e}set primaryKeyField(e){this._setSetting("primaryKeyField",e)}get displayField(){return this._getSetting("displayField",this.primaryKeyField)}set displayField(e){!this._featureSettings?.popupTemplate||this._featureSettings.popupTemplate.title&&this._featureSettings.popupTemplate.title!==`{${this.displayField}}`||(this._featureSettings.popupTemplate.title=`{${e}}`),this._setSetting("displayField",e)}get geometryType(){return this._getSetting("geometryType")}set geometryType(e){this._setSetting("geometryType",e)}get hasGeometry(){return void 0!==this.geometryType&&null!==this.geometryType}get timeZone(){return this._getSetting("timeZone","UTC")}set timeZone(e){g("timeZone",e).satisfies((e=>F(e)),b(e)),this._setSetting("timeZone",e)}get typeIdField(){return this._getSetting("typeIdField")}set typeIdField(e){this._setSetting("typeIdField",e)}get types(){return this._getCollectionSetting("types")}get _fields(){return this._getCollectionSetting("_fields")}constructor(e){super(e),this.fieldExtensions=new A(this),this.fields=new k(this)}static createFieldInfoFromField(e){let t=!0;const i=e.name.toLowerCase();return("oid"===e.type||"geometry"===e.type||N.has(i)&&N.get(i)===e.type)&&(t=!1),new l({visible:t,fieldName:e.name,format:void 0,label:e.alias,stringFieldOption:void 0,tooltip:void 0,isEditable:e.editable})}findFieldByName(e){return this.fields.find((t=>I(t.name,e)))}toJSON(e="all"){const t=p(this._getSerializableProperties(),this,e)||{};let i=t.fieldExtensions;this.parent&&(i=i?.filter((e=>{const t=this.parent;return!t?.fieldExtensions?.some((t=>t.id===e.id))})));const{fields:s}=t;if(t)for(const e of Object.keys(t))this.isModified(e)||delete t[e];if(s&&(t.fields=s),i?.length&&(t.fieldExtensions=i),!c(e)||!m(t))return t}createPopupTemplate(){const e=this.createAllFieldInfos();return new i({fieldInfos:e,content:[{type:"fields"},{type:"attachments"}]})}createAllFieldInfos(){return this.fields.toArray().filter((e=>!!e.name)).map((t=>e.createFieldInfoFromField(t)))}_getSerializableProperties(){return{geometryType:{serialize:!1,deserialize:e=>{this.geometryType=e?a(e):void 0}},spatialReference:{serialize:!1},primaryKeyField:{serialize:!1},displayField:{serialize:!1},typeIdField:{serialize:!1},fields:{serializeModes:["initial"],serialize:()=>this.isModified("_fields")?this.fields.toArray().map((e=>e.toJSON())):void 0,deserialize:e=>{if(!e)return;const t=e.map((e=>v(e)?e:n.fromJSON(e)));y(this.fields,t,{onNew:(e,t)=>{this.fields.add(e,t)},onMatch:(e,t,i,s)=>{e!==t&&(e.alias=t.alias,e.editable=t.editable,e.length=t.length,e.nullable=t.nullable,e.type=t.type),i!==s&&this.fields.reorder(e,s)},onMissing:e=>{this.fields.remove(e)},equals:(e,t)=>e.name===t.name})}},fieldExtensions:{serializeModes:["initial"],serialize:e=>this.fieldExtensions.toArray().map((t=>t.toJSON(e))).filter((e=>this._alwaysSerializeFieldExtensions||!(e&&2===Object.keys(e).length&&e.id&&e.field))),deserialize:e=>{e&&y(this.fieldExtensions,e,{onNew:(e,t)=>{this.fieldExtensions.add(d(e)?e:new E(e),t)},onMatch:(e,t,i,s)=>{d(t)||e.assignProperties(t),i!==s&&this.fieldExtensions.reorder(e,s)},onMissing:e=>{this._alwaysSerializeFieldExtensions&&this.fieldExtensions.remove(e)},equals:(e,t)=>d(t)?t===e:!(!t?.field||!E.matchesRef(e,t.field))||e.id===t.id})}},types:{serialize:!1,deserialize:e=>{if(!e)return;const t=e.map((e=>x(e)||!e?e:o.fromJSON(e)));y(this.types,t,{onNew:(e,t)=>{this.types.add(e,t)},onMatch:(e,t,i,s)=>{e!==t&&(e.name=t.name,e.templates=t.templates?[...t.templates]:[],e.domains=t.domains),i!==s&&this.types.reorder(e,s)},onMissing:e=>{this.types.remove(e)},equals:(e,t)=>e.id===t.id})}},timeZone:{serialize:!1,deserialize:e=>{e&&(this.timeZone=e)}}}}};M=e=t([f],M);export{M as Schema};class k extends _{get _createFieldLookup(){return this._collection.reduce(((e,t)=>(e.add(t),e)),new WeakSet)}get _expressionFieldsLength(){return this.expressionFields.length}get expressionFields(){if(!this._popupTemplate?.fieldInfos||!this._popupTemplate?.expressionInfos)return new s;const e=new s;for(const t of this._popupTemplate.fieldInfos){const i=t.fieldName.match(S);if(i){const s=this._popupTemplate.expressionInfos.find((e=>e.name===i[1]));if(s){if(!j.has(t)){const e=new n({name:t.fieldName,alias:t.label||s.title||t.fieldName,type:"number"===s.returnType?"double":"string",editable:!1});j.set(t,e)}e.add(j.get(t))}}}return e}get _collection(){return this._schema._fields.concat(this.expressionFields)}get _popupTemplate(){return this._schema._featureSettings?this._schema._featureSettings.popupTemplate:void 0}constructor(e){super(),this._schema=e,T(this._schema,"_fields",(e=>{this.emit("change",e),this._fieldLookup=void 0})),e.watch("_fields.length",(()=>this.notifyChange("length")))}includes(e){return this._fieldLookup=this._fieldLookup??this._createFieldLookup,this._fieldLookup.has(e)}clone(){return new k(this._schema)}add(e,t){g("field",e).isNotMissing(),this._fieldLookup=void 0;const i=e.name?e.name.match(S):void 0;if(i){if(!this._popupTemplate)throw new r("Cannot create a field that references an arcade expression without a feature source and popup template.");const t=this._popupTemplate.expressionInfos.find((e=>e.name===i[1]));if(!t)throw new r("Cannot create a field that references a non-existent arcade expression.");this._popupTemplate.fieldInfos||(this._popupTemplate.fieldInfos=[]);let s=this._popupTemplate.fieldInfos.find((t=>t.fieldName===e.name));s||(s=new l({fieldName:e.name,label:t.title}),this._popupTemplate.fieldInfos.push(s));const o=j.get(s);j.set(s,e);const n={added:[e],moved:[],removed:o?[o]:[],target:this};this.emit("change",n),this.notifyChange("length"),this.notifyChange("_expressionFieldsLength")}else this._schema._fields.add(e,t);return this}removeAt(e){g("index",e).isNotMissing();const t=this.getItemAt(e);if(!t)return;this._fieldLookup=void 0;if(t.name?t.name.match(S):void 0){const e=this._popupTemplate.fieldInfos.findIndex((e=>e.fieldName===t.name));this._popupTemplate.fieldInfos.splice(e,1);const i={added:[],moved:[],removed:[t],target:this};this.emit("change",i),this.notifyChange("length"),this.notifyChange("_expressionFieldsLength")}else this._schema._fields.remove(t);return t}reorder(e,t){if(e&&this._schema._fields.includes(e))return this._schema._fields.reorder(e,t),e}sort(e){return this._schema._fields.sort(e),this}}class A extends h{get _collection(){return this._schema.fields.map((e=>this._forField(e))).concat(Array.from(this._uninitializedFieldExtensions))}constructor(e){super(),this._uninitializedFieldExtensions=new Set,this._schema=e,T(this._schema,"fields",(e=>{const t={added:(e.added||[]).map((e=>this._forField(e))),moved:(e.moved||[]).map((e=>this._forField(e))),removed:(e.removed||[]).map((e=>this._forField(e))),target:this};this.emit("change",t)})),e.watch("fields.length",(()=>this.notifyChange("length")))}forField(e){if(g("field",e).isNotMissing(),this._schema.fields.includes(e))return this._forField(e)}add(e,t){if(g("fieldX",e).isNotMissing(),e.schema&&e.schema.fieldExtensions.remove(e),e._setSchema(this._schema),e.field){const i=w.get(e.field);if(w.set(e.field,e),i&&i!==e&&this._onRemoved(i),this._schema.fields.includes(e.field))if(void 0===t){const t={added:[e],moved:[],removed:i?[i]:[],target:this};this.emit("change",t)}else this._schema.fields.reorder(e.field,t);else this._schema.fields.add(e.field,t)}else{this._uninitializedFieldExtensions.add(e);const t={added:[e],moved:[],removed:[],target:this};this.emit("change",t)}return this._onAdded(e),this}removeAt(e){const t=this.getItemAt(e);if(void 0!==t){if(this._uninitializedFieldExtensions.has(t)){this._uninitializedFieldExtensions.delete(t);const e={added:[],moved:[],removed:[t],target:this};this.emit("change",e)}else this._schema.fields.remove(t.field);return this._onRemoved(t),t}}reorder(e,t){if(e&&this._schema.fields.includes(e.field))return this._schema.fields.reorder(e.field,t),e}sort(e){return this._schema.fields.sort(((t,i)=>e(this._forField(t),this._forField(i)))),this}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.field}_onAdded(e){}_onRemoved(e){e.schema===this._schema&&e._setSchema(void 0)}_forField(e){if(this._uninitializedFieldExtensions.size)for(const e of this._uninitializedFieldExtensions)e._resolveField(),e.field&&(w.set(e.field,e),this._uninitializedFieldExtensions.delete(e));if(!w.has(e)){const t=new E({field:e});w.set(e,t),t._setSchema(this._schema),this._onAdded(t)}return w.get(e)}}
|
|
1
|
+
var e;import{__decorate as t}from"tslib";import i from"@arcgis/core/PopupTemplate";import s from"@arcgis/core/core/Collection";import o from"@arcgis/core/layers/support/FeatureType";import n from"@arcgis/core/layers/support/Field";import l from"@arcgis/core/popup/FieldInfo";import{InvalidOperationError as r}from"../InvalidOperationError.js";import{isFieldExtension as d}from"../ItemType.js";import{jsonToGeometryType as a}from"../json/GeometryJson.js";import{InitializableCollectionProxy as h}from"../support/InitializableCollectionProxy.js";import{filterJSONProperties as p,isDefault as m,serializable as f,shouldExcludeDefaults as c}from"../support/Serializable.js";import{Settings as u}from"../support/Settings.js";import{CollectionProxy as _}from"../utilities/CollectionProxy.js";import{checkArg as g}from"../utilities/checkArg.js";import{compare as y}from"../utilities/collection.js";import{isValidTimeZone as F,ERR_TIME_ZONE_INVALID as b}from"../utilities/date.js";import{isFeatureType as x,isField as v}from"../utilities/esri.js";import{fieldWithArcadeXRegex as S,fieldWithRelationshipRegex as z}from"../utilities/field.js";import{caseInsensitiveEquals as I}from"../utilities/string.js";import{onCollectionPropertyChange as T}from"../utilities/watch.js";import{_fieldExtensionMap as w,FieldExtension as E}from"./FieldExtension.js";const N=new Map;N.set("objectid","oid"),N.set("oid","oid"),N.set("fid","oid"),N.set("shape","geometry"),N.set("shape__length","double"),N.set("shape_length","double"),N.set("shape__area","double"),N.set("shape_area","double"),N.set("area","double"),N.set("perimeter","double"),N.set("length","double"),N.set("fnode_","double"),N.set("tnode_","double"),N.set("lpoly_","double"),N.set("rpoly_","double"),N.set("cover_","integer"),N.set("cover_id","integer"),N.set("idtic","integer"),N.set("xtic","double"),N.set("ytic","double"),N.set("xmin","double"),N.set("ymin","double"),N.set("xmax","double"),N.set("ymax","double"),N.set("arc_","double"),N.set("subclass_","integer"),N.set("subclass_id","integer"),N.set("routelink","integer"),N.set("arclink","integer"),N.set("f_meas","double"),N.set("t_meas","double"),N.set("f_pos","double"),N.set("t_pos","double"),N.set("f_meas","double"),N.set("globalid","global-id"),N.set("guid","guid");export{S as fieldWithArcadeXRegex,z as fieldWithRelationshipRegex};const j=new WeakMap;let M=e=class extends u{get spatialReference(){return this._getSetting("spatialReference")}set spatialReference(e){this._setSetting("spatialReference",e)}get primaryKeyField(){const e=this._getSetting("primaryKeyField");if(!e){const e=this.fields.filter((e=>"oid"===e.type));if(1===e.length)return e.getItemAt(0).name}return e}set primaryKeyField(e){this._setSetting("primaryKeyField",e)}get displayField(){return this._getSetting("displayField",this.primaryKeyField)}set displayField(e){!this._featureSettings?.popupTemplate||this._featureSettings.popupTemplate.title&&this._featureSettings.popupTemplate.title!==`{${this.displayField}}`||(this._featureSettings.popupTemplate.title=`{${e}}`),this._setSetting("displayField",e)}get geometryType(){return this._getSetting("geometryType")}set geometryType(e){this._setSetting("geometryType",e)}get hasGeometry(){return void 0!==this.geometryType&&null!==this.geometryType}get timeZone(){return this._getSetting("timeZone","UTC")}set timeZone(e){g("timeZone",e).satisfies((e=>F(e)),b(e)),this._setSetting("timeZone",e)}get typeIdField(){return this._getSetting("typeIdField")}set typeIdField(e){this._setSetting("typeIdField",e)}get types(){return this._getCollectionSetting("types")}get _fields(){return this._getCollectionSetting("_fields")}constructor(e){super(e),this.fieldExtensions=new A(this),this.fields=new k(this)}static createFieldInfoFromField(e){let t=!0;const i=e.name.toLowerCase();return("oid"===e.type||"geometry"===e.type||N.has(i)&&N.get(i)===e.type)&&(t=!1),new l({visible:t,fieldName:e.name,format:void 0,label:e.alias,stringFieldOption:void 0,tooltip:void 0,isEditable:e.editable})}findFieldByName(e){return this.fields.find((t=>I(t.name,e)))}toJSON(e="all"){const t=p(this._getSerializableProperties(),this,e)||{};let i=t.fieldExtensions;this.parent&&(i=i?.filter((e=>{const t=this.parent;return!t?.fieldExtensions?.some((t=>t.id===e.id))})));const{fields:s}=t;if(t)for(const e of Object.keys(t))this.isModified(e)||delete t[e];if(s&&(t.fields=s),i?.length&&(t.fieldExtensions=i),!c(e)||!m(t))return t}createPopupTemplate(){const e=this.createAllFieldInfos();return new i({fieldInfos:e,content:[{type:"fields"},{type:"attachments"}]})}createAllFieldInfos(){return this.fields.toArray().filter((e=>!!e.name)).map((t=>e.createFieldInfoFromField(t)))}_getSerializableProperties(){return{geometryType:{serialize:!1,deserialize:e=>{this.geometryType=e?a(e):void 0}},spatialReference:{serialize:!1},primaryKeyField:{serialize:!1},displayField:{serialize:!1},typeIdField:{serialize:!1},fields:{serializeModes:["initial"],serialize:()=>this.isModified("_fields")?this.fields.toArray().map((e=>e.toJSON())):void 0,deserialize:e=>{if(!e)return;const t=e.map((e=>v(e)?e:n.fromJSON(e)));y(this.fields,t,{onNew:(e,t)=>{this.fields.add(e,t)},onMatch:(e,t,i,s)=>{e!==t&&(e.alias=t.alias,e.editable=t.editable,e.length=t.length,e.nullable=t.nullable,e.type=t.type),i!==s&&this.fields.reorder(e,s)},onMissing:e=>{this.fields.remove(e)},equals:(e,t)=>I(e.name,t.name)})}},fieldExtensions:{serializeModes:["initial"],serialize:e=>this.fieldExtensions.toArray().map((t=>t.toJSON(e))).filter((e=>this._alwaysSerializeFieldExtensions||!(e&&2===Object.keys(e).length&&e.id&&e.field))),deserialize:e=>{e&&y(this.fieldExtensions,e,{onNew:(e,t)=>{this.fieldExtensions.add(d(e)?e:new E(e),t)},onMatch:(e,t,i,s)=>{d(t)||e.assignProperties(t),i!==s&&this.fieldExtensions.reorder(e,s)},onMissing:e=>{this._alwaysSerializeFieldExtensions&&this.fieldExtensions.remove(e)},equals:(e,t)=>d(t)?t===e:!(!t?.field||!E.matchesRef(e,t.field))||e.id===t.id})}},types:{serialize:!1,deserialize:e=>{if(!e)return;const t=e.map((e=>x(e)||!e?e:o.fromJSON(e)));y(this.types,t,{onNew:(e,t)=>{this.types.add(e,t)},onMatch:(e,t,i,s)=>{e!==t&&(e.name=t.name,e.templates=t.templates?[...t.templates]:[],e.domains=t.domains),i!==s&&this.types.reorder(e,s)},onMissing:e=>{this.types.remove(e)},equals:(e,t)=>e.id===t.id})}},timeZone:{serialize:!1,deserialize:e=>{e&&(this.timeZone=e)}}}}};M=e=t([f],M);export{M as Schema};class k extends _{get _createFieldLookup(){return this._collection.reduce(((e,t)=>(e.add(t),e)),new WeakSet)}get _expressionFieldsLength(){return this.expressionFields.length}get expressionFields(){if(!this._popupTemplate?.fieldInfos||!this._popupTemplate?.expressionInfos)return new s;const e=new s;for(const t of this._popupTemplate.fieldInfos){const i=t.fieldName.match(S);if(i){const s=this._popupTemplate.expressionInfos.find((e=>e.name===i[1]));if(s){if(!j.has(t)){const e=new n({name:t.fieldName,alias:t.label||s.title||t.fieldName,type:"number"===s.returnType?"double":"string",editable:!1});j.set(t,e)}e.add(j.get(t))}}}return e}get _collection(){return this._schema._fields.concat(this.expressionFields)}get _popupTemplate(){return this._schema._featureSettings?this._schema._featureSettings.popupTemplate:void 0}constructor(e){super(),this._schema=e,T(this._schema,"_fields",(e=>{this.emit("change",e),this._fieldLookup=void 0})),e.watch("_fields.length",(()=>this.notifyChange("length")))}includes(e){return this._fieldLookup=this._fieldLookup??this._createFieldLookup,this._fieldLookup.has(e)}clone(){return new k(this._schema)}add(e,t){g("field",e).isNotMissing(),this._fieldLookup=void 0;const i=e.name?e.name.match(S):void 0;if(i){if(!this._popupTemplate)throw new r("Cannot create a field that references an arcade expression without a feature source and popup template.");const t=this._popupTemplate.expressionInfos.find((e=>e.name===i[1]));if(!t)throw new r("Cannot create a field that references a non-existent arcade expression.");this._popupTemplate.fieldInfos||(this._popupTemplate.fieldInfos=[]);let s=this._popupTemplate.fieldInfos.find((t=>I(t.fieldName,e.name)));s||(s=new l({fieldName:e.name,label:t.title}),this._popupTemplate.fieldInfos.push(s));const o=j.get(s);j.set(s,e);const n={added:[e],moved:[],removed:o?[o]:[],target:this};this.emit("change",n),this.notifyChange("length"),this.notifyChange("_expressionFieldsLength")}else this._schema._fields.add(e,t);return this}removeAt(e){g("index",e).isNotMissing();const t=this.getItemAt(e);if(!t)return;this._fieldLookup=void 0;if(t.name?t.name.match(S):void 0){const e=this._popupTemplate.fieldInfos.findIndex((e=>I(e.fieldName,t.name)));this._popupTemplate.fieldInfos.splice(e,1);const i={added:[],moved:[],removed:[t],target:this};this.emit("change",i),this.notifyChange("length"),this.notifyChange("_expressionFieldsLength")}else this._schema._fields.remove(t);return t}reorder(e,t){if(e&&this._schema._fields.includes(e))return this._schema._fields.reorder(e,t),e}sort(e){return this._schema._fields.sort(e),this}}class A extends h{get _collection(){return this._schema.fields.map((e=>this._forField(e))).concat(Array.from(this._uninitializedFieldExtensions))}constructor(e){super(),this._uninitializedFieldExtensions=new Set,this._schema=e,T(this._schema,"fields",(e=>{const t={added:(e.added||[]).map((e=>this._forField(e))),moved:(e.moved||[]).map((e=>this._forField(e))),removed:(e.removed||[]).map((e=>this._forField(e))),target:this};this.emit("change",t)})),e.watch("fields.length",(()=>this.notifyChange("length")))}forField(e){if(g("field",e).isNotMissing(),this._schema.fields.includes(e))return this._forField(e)}add(e,t){if(g("fieldX",e).isNotMissing(),e.schema&&e.schema.fieldExtensions.remove(e),e._setSchema(this._schema),e.field){const i=w.get(e.field);if(w.set(e.field,e),i&&i!==e&&this._onRemoved(i),this._schema.fields.includes(e.field))if(void 0===t){const t={added:[e],moved:[],removed:i?[i]:[],target:this};this.emit("change",t)}else this._schema.fields.reorder(e.field,t);else this._schema.fields.add(e.field,t)}else{this._uninitializedFieldExtensions.add(e);const t={added:[e],moved:[],removed:[],target:this};this.emit("change",t)}return this._onAdded(e),this}removeAt(e){const t=this.getItemAt(e);if(void 0!==t){if(this._uninitializedFieldExtensions.has(t)){this._uninitializedFieldExtensions.delete(t);const e={added:[],moved:[],removed:[t],target:this};this.emit("change",e)}else this._schema.fields.remove(t.field);return this._onRemoved(t),t}}reorder(e,t){if(e&&this._schema.fields.includes(e.field))return this._schema.fields.reorder(e.field,t),e}sort(e){return this._schema.fields.sort(((t,i)=>e(this._forField(t),this._forField(i)))),this}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.field}_onAdded(e){}_onRemoved(e){e.schema===this._schema&&e._setSchema(void 0)}_forField(e){if(this._uninitializedFieldExtensions.size)for(const e of this._uninitializedFieldExtensions)e._resolveField(),e.field&&(w.set(e.field,e),this._uninitializedFieldExtensions.delete(e));if(!w.has(e)){const t=new E({field:e});w.set(e,t),t._setSchema(this._schema),this._onAdded(t)}return w.get(e)}}
|
package/data/convert.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@arcgis/core/geometry/Point";import t from"@arcgis/core/geometry/SpatialReference";import{geometryTypeToJson as r}from"../json/GeometryJson.js";import{translate as o}from"../locale/language.js";import{INVARIANT as n}from"../locale.js";import{checkArg as a,assertNever as i}from"../utilities/checkArg.js";import{parse as s,format as c,DEFAULT_PARSING_FORMATS as m,DateFormat as l,INVALID_DATE as u}from"../utilities/date.js";import{isPoint as f,isMultipoint as d,isPolyline as p,isPolygon as y,isExtent as g}from"../utilities/esri.js";import{project as w,esriToWKT as h,wktToEsri as F,esriWkidToWkt as N,esriWktToWkid as S,esriToGeoJSON as O,geoJSONToEsri as T}from"../utilities/geometry.js";import{getLogger as R}from"../utilities/log.js";import{isNumeric as G,parse as D,format as b,NumberFormat as A}from"../utilities/number.js";import{caseInsensitiveEquals as E}from"../utilities/string.js";import{Feature as x}from"./Feature.js";import{FeatureSet as M}from"./FeatureSet.js";const I=["=","-","+","@"],_='"',v="\r\n",L="\n",P=[...m.map(pe),"M/d/yy"],C=/(\w+)_(point|multipoint|polyline|polygon)z?/;var U;function $(){return R("geocortex.api.data.convert")}!function(e){e.DATE="D",e.NUMBER="N",e.STRING="C",e.BOOLEAN="L"}(U||(U={}));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 j=[[GeometryFormat.ARCGIS_JSON,ne],[GeometryFormat.GEO_JSON,ae],[GeometryFormat.WKT,ie]],J=new Map(j);export async function uploadDataToFeatureSet(t){const n=await async function(t){const{data:r,includeHeaderRow:o,geometryFormat:n,geometryFields:a,locale:s,numberFormat:c,inSpatialReference:m}=t,l=o?r.slice(1):r;if(n===GeometryFormat.NONE)return{columnIndices:[]};const u=e=>me(e,s,c),f=(t,r)=>{const o=r===GeometryFormat.XYZ,n=r===GeometryFormat.LAT_LON;return{columnIndices:t,geometries:l.map((r=>{if(r.length>=Math.max(...t)&&G(r[t[0]]?.raw,s)&&G(r[t[1]]?.raw,s)&&(!o||G(r[t[2]]?.raw,s)))return new e({x:u(n?r[t[1]].raw:r[t[0]].raw),y:u(n?r[t[0]].raw:r[t[1]].raw),z:o?u(r[t[2]].raw):0,spatialReference:m})}))}},d=async(e,t)=>({columnIndices:[e],geometries:await Promise.all(l.map((t=>t[e])).map((e=>{if(e?.raw)return t(e.raw.toString(),m)})))}),p=async(e,t)=>{switch(t){case GeometryFormat.NONE:return{columnIndices:[0]};case GeometryFormat.LAT_LON:case GeometryFormat.XYZ:case GeometryFormat.XY:return f(e,t);case GeometryFormat.ARCGIS_JSON:return d(e[0],ne);case GeometryFormat.GEO_JSON:return d(e[0],ae);case GeometryFormat.WKT:return d(e[0],ie);default:return i(t,new Error(`Unknown geometry format "${t}".`))}};if(n){const e=se(o?r[0]:r[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 p(e??[0],n)}const[y,g]=await le(r,m,o);if(y===GeometryFormat.NONE)return{columnIndices:[]};return g.length>1?f(g,y):d(g[0],J.get(y))}(t),a=function(e,t){const{data:n,displayField:a,includeHeaderRow:i,inSpatialReference:s,outSpatialReference:c,generatePrimaryKey:m}=e,l={fields:[]},u=e=>!(!t.columnIndices||0===t.columnIndices.length)&&t.columnIndices.includes(e);let{primaryKeyField:f}=e,d=0;for(let t=0;t<n[0].length;t++){if(u(t))continue;const r=fe(e,t,!m&&!f&&!l.fields.find((e=>"esriFieldTypeOID"===e.type)));let a=n[0][t]?.raw?.toString(),s=a?.replace(FIELD_NAME_REGEX,"_");i&&s||(s="field"+ ++d,a=o("gcx.api.data.convert.import-field-alias",d)),l.fields.push({alias:a,name:s,type:r}),"esriFieldTypeOID"===r&&(f=s)}if(l.spatialReference=c??t.geometries?.[0]?.spatialReference??s,t.geometries?.length){const e=t.geometries.filter((e=>void 0!==e)).map((e=>e.type)),o=e[0];l.geometryType=e.every((e=>e===o))?r(o):void 0}if(!l.fields.find((e=>"esriFieldTypeOID"===e.type))){const e=l.fields.length+1,t=!!l.fields.find((e=>"objectid"===e.name.toLowerCase()));f=t?`OBJECTID_${e}`:"OBJECTID",l.fields.push({name:f,alias:f,type:"esriFieldTypeOID"})}return l.displayField=a??l.fields.find((e=>e.name!==f&&"esriFieldTypeString"===e.type))?.name??l.fields.find((e=>e.name!==f))?.name??f,l.primaryKeyField=f,l}(t,n),s=await async function(e,t,r){const{data:o,includeHeaderRow:n,outFields:a,escapeFormulaChars:i,locale:s,numberFormat:c,dateFormat:m}=e,{spatialReference:l}=r,u=[],f=n?o.slice(1):o,d=(e,r)=>!t.columnIndices||0===t.columnIndices.length||!t.columnIndices.includes(r);return await Promise.all(f.map((async(e,o)=>{const n=new x;for(let t=0;t<r.fields.length;t++){const l=r.fields[t],u=e.filter(d);if(a.includes("*")||a.includes(l.name)){let e=await de(u[t]?.raw,l,{escapeFormulaChars:i,dateFormat:m,numberFormat:c,locale:s});"esriFieldTypeOID"===l.type&&null===e&&(e=o),n.attributes.set(l.name,e)}}t.geometries&&(n.geometry=await K(t.geometries[o],l)),u.push(n)}))),u}(t,n,a);return new M({features:s,schema:a})}export async function toCsv(e,r){a("featureSet",e).isNotMissing();const o=Array.from(e),n={...{useFormattedValues:!1,alwaysQuote:!1,escapeFormulaChars:!0,delimiter:",",dateFormat:l.ROUND_TRIP,geometryFormat:o.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,includeByteOrderMark:!0,outSpatialReference:t.WGS84,includeHeaderRow:!0,outFields:B(e.source),rowDelimiter:navigator.platform.startsWith("Win")?v:L},...r},{includeByteOrderMark:i,includeHeaderRow:s,delimiter:c,outFields:m,rowDelimiter:u}=n,f=[];i&&f.push("\ufeff");const d=Y(o,n),p=k(o,m,e.schema,!0),y=k(o,m,e.schema,!1);if(s){const e=[];for(const t of d)e.push(V(t,n));for(const t of p)e.push(V(t,n));for(const t of y)e.push(V(t,n));const t=e.join(c)+u;f.push(t)}await Promise.all(o.map((async e=>{const t=[],r=(t,r)=>V(q(Q(e,t,r),r),r);t.push(...await async function(e,t){let r=await Z(e,t);t.geometryFormat!==GeometryFormat.XYZ&&t.geometryFormat!==GeometryFormat.XY&&t.geometryFormat!==GeometryFormat.LAT_LON||(r=r.map((e=>void 0===e?"":q(e,t))));return r.map((e=>""===e?"":V(e,t)))}(e.geometry,n)),t.push(...p.map((e=>r(e,n)))),t.push(...y.map((e=>r(e,n))));const o=`${t.join(c)}${u}`;f.push(o)})));return new Blob(f,{type:"text/plain",endings:u===L||u===v?"transparent":"native"})}export async function csvToUploadData(e,t){let r;if(a("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 i=H(t),s=i.rowDelimiter||function(e){let t=L;return oe(e,v,((r,o)=>(0===r&&o===e.length||(t=v),!1))),t}(r),c=i.delimiter??function(e,t,r){const o=",";if(0===e.length)return o;const a=[];if(oe(e,t,((t,r)=>(r!==e.length||t!==r)&&(a.push(e.substring(t,r)),a.length<3))),0===a.length)return o;let i=[{delimiter:",",rowsDelimiterOccurrences:[],rowsNumberAdjacentOccurrences:[]},{delimiter:";",rowsDelimiterOccurrences:[]},{delimiter:"|",rowsDelimiterOccurrences:[]},{delimiter:"\t",rowsDelimiterOccurrences:[]},{delimiter:" ",rowsDelimiterOccurrences:[]}].filter((e=>a[0].includes(e.delimiter)));if(0===i.length)return o;for(const e of a)for(const t of i){let o=0,n=0;oe(e,t.delimiter,((a,i)=>{if(i!==e.length&&o++,","===t.delimiter){const t=e.charAt(i-1),o=e.charAt(i+1);G(t,r)&&G(o,r)&&n++}return!0})),t.rowsDelimiterOccurrences.push(o),","===t.delimiter&&t.rowsNumberAdjacentOccurrences.push(n)}if(i=i.filter((e=>e.rowsDelimiterOccurrences.every((t=>e.rowsDelimiterOccurrences[0]===t)))).sort(((e,t)=>t.rowsDelimiterOccurrences[0]-e.rowsDelimiterOccurrences[0])),i.length>1&&","===i[0].delimiter&&null!=r&&r!==n){const e=i[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]){i=i.filter((e=>","!==e.delimiter));break}}if(0===i.length)return o;return i[0].delimiter}(r,s,t.locale),m=function(e,t,r){const o=[],n=(e,t)=>{const o=[];return oe(e,r,((r,n)=>{const a=e.substring(r,n);return o.push({raw:re(a,t,o.length)}),!0})),o};if(oe(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,s,c);let{geometryFormat:l,geometryFields:u}=t;if(!l){const[e,t]=await le(m,i.inSpatialReference,i.includeHeaderRow);l=e,u=t.map((e=>i.includeHeaderRow?m[0][e]?.raw??o("gcx.api.data.convert.import-field-alias",(e+1).toString()):o("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:m,...i,geometryFormat:l,geometryFields:u}}export async function csvToFeatureSet(e,t){const r=H(t);return uploadDataToFeatureSet(await csvToUploadData(e,r))}export async function toXLSX(e,r){a("featureSet",e).isNotMissing();const o=Array.from(e),n={...{useFormattedValues:!1,includeHeaderRow:!0,escapeFormulaChars:!0,geometryFormat:o.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,outFields:B(e.source),outSpatialReference:t.WGS84,dateFormat:l.DEFAULT,numberFormat:A.DEFAULT,sheetName:"sheet1"},...r},{outFields:i,includeHeaderRow:s,dateFormat:c,numberFormat:m}=n,u=[],f=Y(o,n),d=k(o,i,e.schema,!0),p=k(o,i,e.schema,!1);if(s){const t=f.concat(d).concat(function(e,t){const r=t?.schema?.fieldExtensions.initializedItems.map((e=>e.field));return e.map((e=>r?.find((t=>t.name===e))?.alias??e))}(p,e.source));u.push(t)}await Promise.all(o.map((async e=>{const t=[];t.push(...await Z(e.geometry,n));for(const r of d){const o=ge(e.attributes.get(r),n);t.push(o)}for(const r of p){const o=ge(Q(e,r,n),n);t.push(o)}t.every((e=>"string"!=typeof e||e.length<=32767))?u.push(t):$().warn(`toXLSX cell limit exceeded, feature (${e.primaryKey??e.id}) omitted.`)})));const y=await import("xlsx"),g={SheetNames:[],Sheets:{}},w=y.utils.aoa_to_sheet(u,{cellDates:!0});for(const e of Object.keys(w).filter((e=>!e.startsWith("!")))){const t=w[e];"d"===t.t?t.z=pe(c??l.ROUND_TRIP):"n"===t.t&&(t.z=ye(m))}g.SheetNames.push(n.sheetName),g.Sheets[n.sheetName]=w;const h=y.write(g,{type:"binary",bookType:"xlsx",compression:!0,bookSST:!0,cellDates:!0}),F=new Uint8Array(h.length);for(let e=0;e<h.length;e++)F[e]=h.charCodeAt(e);return new Blob([F.buffer],{type:"text/plain"})}export async function xlsxToUploadData(e,t){a("xlsxData",e).isNotMissing();const r=X(t),n=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})}`];t.push(a?{raw:a.v,formatted:"s"===a.t?void 0:a.w}:{raw:""})}i.push(t)}return i}(e,r);let{geometryFormat:i,geometryFields:s}=t;if(!i){const[e,t]=await le(n,r.inSpatialReference,r.includeHeaderRow);i=e,s=t.map((e=>r.includeHeaderRow?n[0][e]?.raw.toString()??o("gcx.api.data.convert.import-field-alias",(e+1).toString()):o("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:n,...r,geometryFormat:i,geometryFields:s}}export async function xlsxToFeatureSet(e,t){a("xlsxData",e).isNotMissing();const r=X(t);return uploadDataToFeatureSet(await xlsxToUploadData(e,r))}export async function toShapefile(e,r){a("featureSet",e).isNotMissing();const[{default:o},n]=await Promise.all([import("jszip"),import("../forked-libs/shp-write/index.js")]),i=Array.from(e),s={...{useFormattedValues:!1,outFields:B(e.source),fileName:e.title||"export"},...r},{outFields:c,outSpatialReference:m,fileName:l}=s,u=e=>e.geometry.hasZ||e.geometry.hasM,w=new Map,h=i.filter((e=>f(e.geometry)));w.set("POINTZ",h.filter(u)),w.set("POINT",h.filter((e=>!u(e))));const F=i.filter((e=>d(e.geometry)));w.set("MULTIPOINTZ",F.filter(u)),w.set("MULTIPOINT",F.filter((e=>!u(e))));const S=i.filter((e=>p(e.geometry)));w.set("POLYLINEZ",S.filter(u)),w.set("POLYLINE",S.filter((e=>!u(e))));const O=i.filter((e=>y(e.geometry)||g(e.geometry)));w.set("POLYGONZ",O.filter(u)),w.set("POLYGON",O.filter((e=>!u(e))));const T=k(i,c,e.schema,!0);let R=k(i,c,e.schema,!1);R=T.concat(R);const G=new o,D=Array.from(w.keys()).filter((e=>w.get(e).length>0));await Promise.all(D.map((async r=>{const o=w.get(r),a=await Promise.all(o.map((e=>K(e.geometry,m)))),i=await async function(e){const{wkid:r,wkt:o}=e[0].spatialReference;if(!e.every((e=>e.spatialReference.wkid===r&&e.spatialReference.wkt===o)))throw new Error("Cannot create shapefile that contains geometries with different spatial references.");return o??await N(r??t.WGS84.wkid)}(a),c=s.useFormattedValues?Object.assign({},...R.map((e=>({[e]:U.STRING})))):function(e,t,r,o){const n={};for(const a of t){if(e.some((e=>ee(e,a)))){n[a]=U.STRING;continue}const t=r?r.fields.find((e=>e.name===a)):void 0;if(t){switch(t.type){case"oid":case"double":case"integer":case"single":case"small-integer":n[a]=U.NUMBER;break;case"date":n[a]=o?U.NUMBER:U.DATE;break;default:n[a]=U.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?U.NUMBER:U.DATE:e.every((e=>"number"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"number"==typeof i(e,a)))?n[a]=U.NUMBER:e.every((e=>"boolean"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"boolean"==typeof i(e,a)))?n[a]=U.BOOLEAN:n[a]=U.STRING}return n}(o,R,e.schema,"timestamp"===s.dateFormat),u=function(e){return e.map((e=>{if(f(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),we(a,e)}if(d(e))return he(e.points,e);if(p(e))return Fe(e.paths,e);if(y(e))return Fe(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.")}))}(a),h=function(e,t,r,o){const n=[];for(const a of e){const e={};for(const n of t){let t=Q(a,n,o);if(null==t&&(t=""),o.useFormattedValues)t=t.toString();else{t=Ne(t,r[n],o)}e[n]=t}n.push(e)}return n}(o,R,c,s);n.write(h,r,u,((e,t)=>{const o=D.length>1?`${l}_${r.toLowerCase()}`:l;G.file(`${o}.shp`,t.shp.buffer,{binary:!0}),G.file(`${o}.shx`,t.shx.buffer,{binary:!0}),G.file(`${o}.dbf`,t.dbf.buffer,{binary:!0}),G.file(`${o}.prj`,i)}))})));const b=await G.generateAsync({type:"uint8array"});return new Blob([b.buffer],{type:"text/plain"})}export async function shapefileToUploadData(r,o){a("shapefileData",r).isNotMissing();const n=z(o),i=new Promise(((e,t)=>{const o=new FileReader;o.onload=()=>{e(o.result)},o.onerror=()=>{t(o.error)},o.readAsArrayBuffer(r)})),[{default:s},{default:c}]=await Promise.all([import("jszip"),import("shpjs")]),m=await i,l=await s.loadAsync(new Uint8Array(m)),u=l.filter((()=>!0)).map((e=>e.name));let d,p=u.filter((e=>e.endsWith(".shp"))).map((e=>e.substring(0,e.length-4)));if(p=function(e){if(!e.length)return[];let t=e[0];const r=t.match(C);return r?(t=r[1],e.filter((e=>{const r=e.match(C);return r&&r[1]===t}))):[t]}(p),u.some((e=>e.endsWith(".prj")))&&!p.every((e=>u.includes(`${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(d){if(t!==d)throw new Error("Shapefile zip must contain the same prj file for each separate shapefile")}else d=t})));let y=[],g=[];for(const e of p){if(!u.includes(`${e}.shx`)||!u.includes(`${e}.dbf`))throw new Error("Shapefile must contain shp, shx, and dbf files.");const t=await l.file(`${e}.shp`).async("uint8array"),r=c.parseShp(t),o=await l.file(`${e}.dbf`).async("uint8array"),n=c.parseDbf(o);if(n.length!==r.length)throw new Error("Shapefile must contain shp, shx, and dbf files.");y=y.concat(n),g=g.concat(r)}const w=await Promise.all(g.map((r=>async function(r,o){const n=f(r)?function(r){a("geometry.coordinates",r.type).matches("Point"),a("geometry.coordinates",r.coordinates).satisfies((e=>"number"==typeof e||Array.isArray(e)));const[o,n,i]=r.coordinates,s=new e({x:o,y:n,spatialReference:t.WGS84});if(Array.isArray(i)){const[e,t]=i;!e&&!t||e?s.z=e:s.m=t}return s}(r):await T(r);if(o){let e;try{const r=await S(o);e=new t({wkid:D(r)})}catch{}e||(e=new t({wkt:o})),n.spatialReference=e}return n}(r,d)))),h=geometryTypeHeaders[GeometryFormat.ARCGIS_JSON][0][0];y.forEach(((e,t)=>e[h]=JSON.stringify(w[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]})))))]}(y),...n,includeHeaderRow:!0,geometryFormat:GeometryFormat.ARCGIS_JSON,geometryFields:[h],inSpatialReference:w[0]?.spatialReference??t.fromJSON({wkid:4326})}}export async function shapefileToFeatureSet(e,t){a("shapefileData",e).isNotMissing();const r=z(t);return uploadDataToFeatureSet(await shapefileToUploadData(e,r))}function W(e){return{escapeFormulaChars:!0,outFields:["*"],generatePrimaryKey:!1,locale:n,detectOid:!e?.primaryKeyField}}function H(e){return{...{includeHeaderRow:!0,inSpatialReference:t.WGS84,...W(e)},...e}}function X(e){return{...{includeHeaderRow:!0,inSpatialReference:t.WGS84,...W(e)},...e}}function z(e){return{...{...W(e)},...e}}function Y(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 k(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 B(e){if(!e)return["*"];const t=e.featureSettings.popupTemplate?.content;return(Array.isArray(t)?t.find((e=>"fields"===e.type))?.fieldInfos?.filter((e=>e.visible))?.map((e=>e.fieldName)):void 0)??e.featureSettings.popupTemplate?.fieldInfos?.filter((e=>e.visible))?.map((e=>e.fieldName))??["*"]}async function Z(e,t){const r=await K(e,t.outSpatialReference);if(t.geometryFormat===GeometryFormat.XYZ){if(!r)return["","",""];if(!f(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(!f(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(!f(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 h(r)]:[""]:t.geometryFormat===GeometryFormat.GEO_JSON?r?[JSON.stringify(await O(r))]:[""]:[]}async function K(e,t){return e?.spatialReference&&!e.spatialReference.equals(t)&&t?(await w([e],t))[0]:e}function V(e,t){const r=[t.delimiter,_,"\r","\n",t.rowDelimiter];if(t.alwaysQuote||r.some((t=>e.includes(t)))){const t=e.replace(new RegExp(_,"g"),`${_}${_}`);return`${_}${t}${_}`}return e}function q(e,t){if(null==e)return"";if(!t.useFormattedValues){if("number"==typeof e){const r=t.numberFormat||A.ROUND_TRIP;return b(r,e)}if(e instanceof Date)return"timestamp"===t.dateFormat?e.getTime().toString():c({format:t.dateFormat,timeZone:"UTC"},e)}let r=e.toString();return t.escapeFormulaChars&&(r=te(r)),r}function Q(e,t,r){if(r.useFormattedValues||ee(e,t))return e.presentableAttributes.get(t)??e.attributes.get(t);if("date"===e.schema.findFieldByName(t)?.type){const r=s(e.attributes.get(t));if(!isNaN(r.getTime()))return r}return e.attributes.get(t)??e.presentableAttributes.get(t)}function ee(e,t){return!!E(t,e.schema.typeIdField)||("coded-value"===e.type?.domains?.[t]?.type||"coded-value"===e.schema.findFieldByName(t)?.domain?.type)}function te(e){for(const t of I)if(e.startsWith(t))return`\t${e}`;return e}function re(e,t,r){const o=e.startsWith(_),n=e.endsWith(_);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(_.length,e.length-_.length):e;let i=-1;return oe(a,_,((e,o)=>{if(o===a.length)return!0;if(i<0){if(o!==a.length)return i=o,!0}else if(o===i+_.length)return i=-1,!0;throw new Error(`Detected invalid CSV: Non-escaped quote for value at row:${t} column:${r}`)})),a.replace(new RegExp(`${_}${_}`,"g"),_)}function oe(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(_)?(n=!n,t+=_.length):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 ne(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 ae(e,t){const r=await T(JSON.parse(e));return r.spatialReference=t,r}async function ie(e,t){const r=await F(e);return r.spatialReference=t,r}function se(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 ce(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 me(e,t,r){return"inv"===t?"string"==typeof e?parseFloat(e.replaceAll(",","")):e:D({locale:t,format:r},e)}async function le(e,t,r){const o=r?e.slice(1):e;if(r){const r=se(e[0],GeometryFormat.ARCGIS_JSON);if(void 0!==r)for(const[e,n]of j){try{await ue(r[0],n,t,o)}catch(e){continue}return[e,[r[0]]]}const n=[GeometryFormat.XYZ,GeometryFormat.XY,GeometryFormat.LAT_LON];for(const t of n){const r=se(e[0],t);if(void 0!==r)return[t,r]}}for(const[e,r]of j){const n=await ce(o[0],r);if(void 0!==n){try{await ue(n,r,t,o)}catch(e){continue}return[e,[n]]}}return[GeometryFormat.NONE,[]]}async function ue(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 fe(e,t,r){let o=!1,n=!0,a=!0,i=!0;const c=new Set,{data:l,includeHeaderRow:f,dateFormat:d,primaryKeyField:p,locale:y}=e,g=f?l[0]:[],w=f?l.slice(1):l;for(const e of w){const r=e[t];r?.raw&&(c.add(r.raw),o=!0,n&&(n=G(r.raw,y)||Number.isNaN(r.raw)),a&&(a=r.raw instanceof Date||s(d||m,r.raw)!==u),i&&(i=s(d||P,r.formatted)!==u))}const h=c.size===w.length;return p&&g[t]?.raw===p||r&&o&&h&&n?"esriFieldTypeOID":o&&i?"esriFieldTypeDate":o&&n?"esriFieldTypeDouble":o&&a?"esriFieldTypeDate":"esriFieldTypeString"}async function de(e,t,r){const{escapeFormulaChars:o,locale:n,numberFormat:a,dateFormat:i}=r;if("esriFieldTypeDouble"===t.type||"esriFieldTypeOID"===t.type)return"number"==typeof e?e:e?me(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:s({locale:n,format:i},e).getTime()}const c=e?.toString()??"";if(o&&c.startsWith("\t"))for(const e of I)if(c.length>1&&c.charAt(1)===e)return c.substring(1);return c}function pe(e){switch(e){case l.DATE_SHORT:return"dd/MM/yyyy";case l.DATE_LONG:return"MMMM d, yyyy";case l.TIME_SHORT:return"h:mm AM/PM";case l.TIME_LONG:return"h:mm:ss AM/PM";case l.DATE_TIME_SHORT:case l.DEFAULT:return"MMM d yyyy h:mm AM/PM";case l.DATE_TIME_LONG:return"MMMM d yyyy h:mm AM/PM";case l.FULL:return"dddd, MMMM d yyyy h:mm AM/PM";case l.ISO_8601:case l.ROUND_TRIP:return'yyyy-MM-dd"T"HH:mm:ss';default:{const t=e.replace(/tt/g,"AM/PM");return t.includes("z")&&$().warn("Warning: Excel will not recognize timezone format 'z', 'zz', or 'zzz'"),t.includes("h")&&!t.includes("AM/PM")&&$().warn("Warning: Excel will interpret 'h' as 'H' if the format does not have an AM/PM designator"),t}}}function ye(e){switch(e){case A.ACCOUNTING:return'_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)';case A.CURRENCY:return'"$"#,##0.00';case A.FIXED_POINT:case A.DEFAULT:return"0.0000";case A.NUMBER:return"#,##0.0000";case A.PERCENT:return"0%";case A.ROUND_TRIP:return"0.00000";default:return e}}function ge(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}let r=e.toString();return t.escapeFormulaChars&&(r=te(r)),r}function we(e,t){return 3===e.length&&!t.hasZ&&t.hasM?[e[0],e[1],void 0,e[2]]:e}function he(e,t){return e.map((e=>we(e,t)))}function Fe(e,t){return e.map((e=>he(e,t)))}function Ne(e,t,r){switch(t){case U.NUMBER:return e instanceof Date?e.getTime():D(e);case U.STRING:return e instanceof Date?c({format:r.dateFormat??l.ROUND_TRIP,timeZone:"UTC"},e):"number"==typeof e?b(r.numberFormat??A.DEFAULT,e):e.toString();case U.BOOLEAN:return!!e;case U.DATE:return s(e);default:return e.toString()}}
|
|
1
|
+
import e from"@arcgis/core/geometry/Point";import t from"@arcgis/core/geometry/SpatialReference";import{geometryTypeToJson as r}from"../json/GeometryJson.js";import{translate as o}from"../locale/language.js";import{INVARIANT as n}from"../locale.js";import{checkArg as a,assertNever as i}from"../utilities/checkArg.js";import{parse as s,format as c,DEFAULT_PARSING_FORMATS as m,DateFormat as l,INVALID_DATE as u}from"../utilities/date.js";import{isPoint as f,isMultipoint as d,isPolyline as p,isPolygon as y,isExtent as g}from"../utilities/esri.js";import{project as w,esriToWKT as h,wktToEsri as F,esriWkidToWkt as N,esriWktToWkid as S,esriToGeoJSON as O,geoJSONToEsri as T}from"../utilities/geometry.js";import{getLogger as R}from"../utilities/log.js";import{isNumeric as G,parse as D,format as b,NumberFormat as A}from"../utilities/number.js";import{caseInsensitiveEquals as E}from"../utilities/string.js";import{Feature as x}from"./Feature.js";import{FeatureSet as M}from"./FeatureSet.js";const I=["=","-","+","@"],_='"',v="\r\n",L="\n",P=[...m.map(pe),"M/d/yy"],C=/(\w+)_(point|multipoint|polyline|polygon)z?/;var U;function $(){return R("geocortex.api.data.convert")}!function(e){e.DATE="D",e.NUMBER="N",e.STRING="C",e.BOOLEAN="L"}(U||(U={}));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 j=[[GeometryFormat.ARCGIS_JSON,ne],[GeometryFormat.GEO_JSON,ae],[GeometryFormat.WKT,ie]],J=new Map(j);export async function uploadDataToFeatureSet(t){const n=await async function(t){const{data:r,includeHeaderRow:o,geometryFormat:n,geometryFields:a,locale:s,numberFormat:c,inSpatialReference:m}=t,l=o?r.slice(1):r;if(n===GeometryFormat.NONE)return{columnIndices:[]};const u=e=>me(e,s,c),f=(t,r)=>{const o=r===GeometryFormat.XYZ,n=r===GeometryFormat.LAT_LON;return{columnIndices:t,geometries:l.map((r=>{if(r.length>=Math.max(...t)&&G(r[t[0]]?.raw,s)&&G(r[t[1]]?.raw,s)&&(!o||G(r[t[2]]?.raw,s)))return new e({x:u(n?r[t[1]].raw:r[t[0]].raw),y:u(n?r[t[0]].raw:r[t[1]].raw),z:o?u(r[t[2]].raw):0,spatialReference:m})}))}},d=async(e,t)=>({columnIndices:[e],geometries:await Promise.all(l.map((t=>t[e])).map((e=>{if(e?.raw)return t(e.raw.toString(),m)})))}),p=async(e,t)=>{switch(t){case GeometryFormat.NONE:return{columnIndices:[0]};case GeometryFormat.LAT_LON:case GeometryFormat.XYZ:case GeometryFormat.XY:return f(e,t);case GeometryFormat.ARCGIS_JSON:return d(e[0],ne);case GeometryFormat.GEO_JSON:return d(e[0],ae);case GeometryFormat.WKT:return d(e[0],ie);default:return i(t,new Error(`Unknown geometry format "${t}".`))}};if(n){const e=se(o?r[0]:r[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 p(e??[0],n)}const[y,g]=await le(r,m,o);if(y===GeometryFormat.NONE)return{columnIndices:[]};return g.length>1?f(g,y):d(g[0],J.get(y))}(t),a=function(e,t){const{data:n,displayField:a,includeHeaderRow:i,inSpatialReference:s,outSpatialReference:c,generatePrimaryKey:m}=e,l={fields:[]},u=e=>!(!t.columnIndices||0===t.columnIndices.length)&&t.columnIndices.includes(e);let{primaryKeyField:f}=e,d=0;for(let t=0;t<n[0].length;t++){if(u(t))continue;const r=fe(e,t,!m&&!f&&!l.fields.find((e=>"esriFieldTypeOID"===e.type)));let a=n[0][t]?.raw?.toString(),s=a?.replace(FIELD_NAME_REGEX,"_");i&&s||(s="field"+ ++d,a=o("gcx.api.data.convert.import-field-alias",d)),l.fields.push({alias:a,name:s,type:r}),"esriFieldTypeOID"===r&&(f=s)}if(l.spatialReference=c??t.geometries?.[0]?.spatialReference??s,t.geometries?.length){const e=t.geometries.filter((e=>void 0!==e)).map((e=>e.type)),o=e[0];l.geometryType=e.every((e=>e===o))?r(o):void 0}if(!l.fields.find((e=>"esriFieldTypeOID"===e.type))){const e=l.fields.length+1,t=!!l.fields.find((e=>"objectid"===e.name.toLowerCase()));f=t?`OBJECTID_${e}`:"OBJECTID",l.fields.push({name:f,alias:f,type:"esriFieldTypeOID"})}return l.displayField=a??l.fields.find((e=>!E(e.name,f)&&"esriFieldTypeString"===e.type))?.name??l.fields.find((e=>!E(e.name,f)))?.name??f,l.primaryKeyField=f,l}(t,n),s=await async function(e,t,r){const{data:o,includeHeaderRow:n,outFields:a,escapeFormulaChars:i,locale:s,numberFormat:c,dateFormat:m}=e,{spatialReference:l}=r,u=[],f=n?o.slice(1):o,d=(e,r)=>!t.columnIndices||0===t.columnIndices.length||!t.columnIndices.includes(r);return await Promise.all(f.map((async(e,o)=>{const n=new x;for(let t=0;t<r.fields.length;t++){const l=r.fields[t],u=e.filter(d);if(a.includes("*")||a.filter((e=>E(e,l.name))).length>0){let e=await de(u[t]?.raw,l,{escapeFormulaChars:i,dateFormat:m,numberFormat:c,locale:s});"esriFieldTypeOID"===l.type&&null===e&&(e=o),n.attributes.set(l.name,e)}}t.geometries&&(n.geometry=await K(t.geometries[o],l)),u.push(n)}))),u}(t,n,a);return new M({features:s,schema:a})}export async function toCsv(e,r){a("featureSet",e).isNotMissing();const o=Array.from(e),n={...{useFormattedValues:!1,alwaysQuote:!1,escapeFormulaChars:!0,delimiter:",",dateFormat:l.ROUND_TRIP,geometryFormat:o.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,includeByteOrderMark:!0,outSpatialReference:t.WGS84,includeHeaderRow:!0,outFields:B(e.source),rowDelimiter:navigator.platform.startsWith("Win")?v:L},...r},{includeByteOrderMark:i,includeHeaderRow:s,delimiter:c,outFields:m,rowDelimiter:u}=n,f=[];i&&f.push("\ufeff");const d=Y(o,n),p=k(o,m,e.schema,!0),y=k(o,m,e.schema,!1);if(s){const e=[];for(const t of d)e.push(V(t,n));for(const t of p)e.push(V(t,n));for(const t of y)e.push(V(t,n));const t=e.join(c)+u;f.push(t)}await Promise.all(o.map((async e=>{const t=[],r=(t,r)=>V(q(Q(e,t,r),r),r);t.push(...await async function(e,t){let r=await Z(e,t);t.geometryFormat!==GeometryFormat.XYZ&&t.geometryFormat!==GeometryFormat.XY&&t.geometryFormat!==GeometryFormat.LAT_LON||(r=r.map((e=>void 0===e?"":q(e,t))));return r.map((e=>""===e?"":V(e,t)))}(e.geometry,n)),t.push(...p.map((e=>r(e,n)))),t.push(...y.map((e=>r(e,n))));const o=`${t.join(c)}${u}`;f.push(o)})));return new Blob(f,{type:"text/plain",endings:u===L||u===v?"transparent":"native"})}export async function csvToUploadData(e,t){let r;if(a("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 i=H(t),s=i.rowDelimiter||function(e){let t=L;return oe(e,v,((r,o)=>(0===r&&o===e.length||(t=v),!1))),t}(r),c=i.delimiter??function(e,t,r){const o=",";if(0===e.length)return o;const a=[];if(oe(e,t,((t,r)=>(r!==e.length||t!==r)&&(a.push(e.substring(t,r)),a.length<3))),0===a.length)return o;let i=[{delimiter:",",rowsDelimiterOccurrences:[],rowsNumberAdjacentOccurrences:[]},{delimiter:";",rowsDelimiterOccurrences:[]},{delimiter:"|",rowsDelimiterOccurrences:[]},{delimiter:"\t",rowsDelimiterOccurrences:[]},{delimiter:" ",rowsDelimiterOccurrences:[]}].filter((e=>a[0].includes(e.delimiter)));if(0===i.length)return o;for(const e of a)for(const t of i){let o=0,n=0;oe(e,t.delimiter,((a,i)=>{if(i!==e.length&&o++,","===t.delimiter){const t=e.charAt(i-1),o=e.charAt(i+1);G(t,r)&&G(o,r)&&n++}return!0})),t.rowsDelimiterOccurrences.push(o),","===t.delimiter&&t.rowsNumberAdjacentOccurrences.push(n)}if(i=i.filter((e=>e.rowsDelimiterOccurrences.every((t=>e.rowsDelimiterOccurrences[0]===t)))).sort(((e,t)=>t.rowsDelimiterOccurrences[0]-e.rowsDelimiterOccurrences[0])),i.length>1&&","===i[0].delimiter&&null!=r&&r!==n){const e=i[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]){i=i.filter((e=>","!==e.delimiter));break}}if(0===i.length)return o;return i[0].delimiter}(r,s,t.locale),m=function(e,t,r){const o=[],n=(e,t)=>{const o=[];return oe(e,r,((r,n)=>{const a=e.substring(r,n);return o.push({raw:re(a,t,o.length)}),!0})),o};if(oe(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,s,c);let{geometryFormat:l,geometryFields:u}=t;if(!l){const[e,t]=await le(m,i.inSpatialReference,i.includeHeaderRow);l=e,u=t.map((e=>i.includeHeaderRow?m[0][e]?.raw??o("gcx.api.data.convert.import-field-alias",(e+1).toString()):o("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:m,...i,geometryFormat:l,geometryFields:u}}export async function csvToFeatureSet(e,t){const r=H(t);return uploadDataToFeatureSet(await csvToUploadData(e,r))}export async function toXLSX(e,r){a("featureSet",e).isNotMissing();const o=Array.from(e),n={...{useFormattedValues:!1,includeHeaderRow:!0,escapeFormulaChars:!0,geometryFormat:o.some((e=>void 0!==e.geometry&&null!==e.geometry))?GeometryFormat.WKT:GeometryFormat.NONE,outFields:B(e.source),outSpatialReference:t.WGS84,dateFormat:l.DEFAULT,numberFormat:A.DEFAULT,sheetName:"sheet1"},...r},{outFields:i,includeHeaderRow:s,dateFormat:c,numberFormat:m}=n,u=[],f=Y(o,n),d=k(o,i,e.schema,!0),p=k(o,i,e.schema,!1);if(s){const t=f.concat(d).concat(function(e,t){const r=t?.schema?.fieldExtensions.initializedItems.map((e=>e.field));return e.map((e=>r?.find((t=>E(t.name,e)))?.alias??e))}(p,e.source));u.push(t)}await Promise.all(o.map((async e=>{const t=[];t.push(...await Z(e.geometry,n));for(const r of d){const o=ge(e.attributes.get(r),n);t.push(o)}for(const r of p){const o=ge(Q(e,r,n),n);t.push(o)}t.every((e=>"string"!=typeof e||e.length<=32767))?u.push(t):$().warn(`toXLSX cell limit exceeded, feature (${e.primaryKey??e.id}) omitted.`)})));const y=await import("xlsx"),g={SheetNames:[],Sheets:{}},w=y.utils.aoa_to_sheet(u,{cellDates:!0});for(const e of Object.keys(w).filter((e=>!e.startsWith("!")))){const t=w[e];"d"===t.t?t.z=pe(c??l.ROUND_TRIP):"n"===t.t&&(t.z=ye(m))}g.SheetNames.push(n.sheetName),g.Sheets[n.sheetName]=w;const h=y.write(g,{type:"binary",bookType:"xlsx",compression:!0,bookSST:!0,cellDates:!0}),F=new Uint8Array(h.length);for(let e=0;e<h.length;e++)F[e]=h.charCodeAt(e);return new Blob([F.buffer],{type:"text/plain"})}export async function xlsxToUploadData(e,t){a("xlsxData",e).isNotMissing();const r=X(t),n=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})}`];t.push(a?{raw:a.v,formatted:"s"===a.t?void 0:a.w}:{raw:""})}i.push(t)}return i}(e,r);let{geometryFormat:i,geometryFields:s}=t;if(!i){const[e,t]=await le(n,r.inSpatialReference,r.includeHeaderRow);i=e,s=t.map((e=>r.includeHeaderRow?n[0][e]?.raw.toString()??o("gcx.api.data.convert.import-field-alias",(e+1).toString()):o("gcx.api.data.convert.import-field-alias",(e+1).toString())))}return{data:n,...r,geometryFormat:i,geometryFields:s}}export async function xlsxToFeatureSet(e,t){a("xlsxData",e).isNotMissing();const r=X(t);return uploadDataToFeatureSet(await xlsxToUploadData(e,r))}export async function toShapefile(e,r){a("featureSet",e).isNotMissing();const[{default:o},n]=await Promise.all([import("jszip"),import("../forked-libs/shp-write/index.js")]),i=Array.from(e),s={...{useFormattedValues:!1,outFields:B(e.source),fileName:e.title||"export"},...r},{outFields:c,outSpatialReference:m,fileName:l}=s,u=e=>e.geometry.hasZ||e.geometry.hasM,w=new Map,h=i.filter((e=>f(e.geometry)));w.set("POINTZ",h.filter(u)),w.set("POINT",h.filter((e=>!u(e))));const F=i.filter((e=>d(e.geometry)));w.set("MULTIPOINTZ",F.filter(u)),w.set("MULTIPOINT",F.filter((e=>!u(e))));const S=i.filter((e=>p(e.geometry)));w.set("POLYLINEZ",S.filter(u)),w.set("POLYLINE",S.filter((e=>!u(e))));const O=i.filter((e=>y(e.geometry)||g(e.geometry)));w.set("POLYGONZ",O.filter(u)),w.set("POLYGON",O.filter((e=>!u(e))));const T=k(i,c,e.schema,!0);let R=k(i,c,e.schema,!1);R=T.concat(R);const G=new o,D=Array.from(w.keys()).filter((e=>w.get(e).length>0));await Promise.all(D.map((async r=>{const o=w.get(r),a=await Promise.all(o.map((e=>K(e.geometry,m)))),i=await async function(e){const{wkid:r,wkt:o}=e[0].spatialReference;if(!e.every((e=>e.spatialReference.wkid===r&&e.spatialReference.wkt===o)))throw new Error("Cannot create shapefile that contains geometries with different spatial references.");return o??await N(r??t.WGS84.wkid)}(a),c=s.useFormattedValues?Object.assign({},...R.map((e=>({[e]:U.STRING})))):function(e,t,r,o){const n={};for(const a of t){if(e.some((e=>ee(e,a)))){n[a]=U.STRING;continue}const t=r?r.fields.find((e=>E(e.name,a))):void 0;if(t){switch(t.type){case"oid":case"double":case"integer":case"single":case"small-integer":n[a]=U.NUMBER;break;case"date":n[a]=o?U.NUMBER:U.DATE;break;default:n[a]=U.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?U.NUMBER:U.DATE:e.every((e=>"number"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"number"==typeof i(e,a)))?n[a]=U.NUMBER:e.every((e=>"boolean"==typeof i(e,a)||void 0===i(e,a)))&&e.some((e=>"boolean"==typeof i(e,a)))?n[a]=U.BOOLEAN:n[a]=U.STRING}return n}(o,R,e.schema,"timestamp"===s.dateFormat),u=function(e){return e.map((e=>{if(f(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),we(a,e)}if(d(e))return he(e.points,e);if(p(e))return Fe(e.paths,e);if(y(e))return Fe(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.")}))}(a),h=function(e,t,r,o){const n=[];for(const a of e){const e={};for(const n of t){let t=Q(a,n,o);if(null==t&&(t=""),o.useFormattedValues)t=t.toString();else{t=Ne(t,r[n],o)}e[n]=t}n.push(e)}return n}(o,R,c,s);n.write(h,r,u,((e,t)=>{const o=D.length>1?`${l}_${r.toLowerCase()}`:l;G.file(`${o}.shp`,t.shp.buffer,{binary:!0}),G.file(`${o}.shx`,t.shx.buffer,{binary:!0}),G.file(`${o}.dbf`,t.dbf.buffer,{binary:!0}),G.file(`${o}.prj`,i)}))})));const b=await G.generateAsync({type:"uint8array"});return new Blob([b.buffer],{type:"text/plain"})}export async function shapefileToUploadData(r,o){a("shapefileData",r).isNotMissing();const n=z(o),i=new Promise(((e,t)=>{const o=new FileReader;o.onload=()=>{e(o.result)},o.onerror=()=>{t(o.error)},o.readAsArrayBuffer(r)})),[{default:s},{default:c}]=await Promise.all([import("jszip"),import("shpjs")]),m=await i,l=await s.loadAsync(new Uint8Array(m)),u=l.filter((()=>!0)).map((e=>e.name));let d,p=u.filter((e=>e.endsWith(".shp"))).map((e=>e.substring(0,e.length-4)));if(p=function(e){if(!e.length)return[];let t=e[0];const r=t.match(C);return r?(t=r[1],e.filter((e=>{const r=e.match(C);return r&&r[1]===t}))):[t]}(p),u.some((e=>e.endsWith(".prj")))&&!p.every((e=>u.includes(`${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(d){if(t!==d)throw new Error("Shapefile zip must contain the same prj file for each separate shapefile")}else d=t})));let y=[],g=[];for(const e of p){if(!u.includes(`${e}.shx`)||!u.includes(`${e}.dbf`))throw new Error("Shapefile must contain shp, shx, and dbf files.");const t=await l.file(`${e}.shp`).async("uint8array"),r=c.parseShp(t),o=await l.file(`${e}.dbf`).async("uint8array"),n=c.parseDbf(o);if(n.length!==r.length)throw new Error("Shapefile must contain shp, shx, and dbf files.");y=y.concat(n),g=g.concat(r)}const w=await Promise.all(g.map((r=>async function(r,o){const n=f(r)?function(r){a("geometry.coordinates",r.type).matches("Point"),a("geometry.coordinates",r.coordinates).satisfies((e=>"number"==typeof e||Array.isArray(e)));const[o,n,i]=r.coordinates,s=new e({x:o,y:n,spatialReference:t.WGS84});if(Array.isArray(i)){const[e,t]=i;!e&&!t||e?s.z=e:s.m=t}return s}(r):await T(r);if(o){let e;try{const r=await S(o);e=new t({wkid:D(r)})}catch{}e||(e=new t({wkt:o})),n.spatialReference=e}return n}(r,d)))),h=geometryTypeHeaders[GeometryFormat.ARCGIS_JSON][0][0];y.forEach(((e,t)=>e[h]=JSON.stringify(w[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]})))))]}(y),...n,includeHeaderRow:!0,geometryFormat:GeometryFormat.ARCGIS_JSON,geometryFields:[h],inSpatialReference:w[0]?.spatialReference??t.fromJSON({wkid:4326})}}export async function shapefileToFeatureSet(e,t){a("shapefileData",e).isNotMissing();const r=z(t);return uploadDataToFeatureSet(await shapefileToUploadData(e,r))}function W(e){return{escapeFormulaChars:!0,outFields:["*"],generatePrimaryKey:!1,locale:n,detectOid:!e?.primaryKeyField}}function H(e){return{...{includeHeaderRow:!0,inSpatialReference:t.WGS84,...W(e)},...e}}function X(e){return{...{includeHeaderRow:!0,inSpatialReference:t.WGS84,...W(e)},...e}}function z(e){return{...{...W(e)},...e}}function Y(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 k(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 B(e){if(!e)return["*"];const t=e.featureSettings.popupTemplate?.content;return(Array.isArray(t)?t.find((e=>"fields"===e.type))?.fieldInfos?.filter((e=>e.visible))?.map((e=>e.fieldName)):void 0)??e.featureSettings.popupTemplate?.fieldInfos?.filter((e=>e.visible))?.map((e=>e.fieldName))??["*"]}async function Z(e,t){const r=await K(e,t.outSpatialReference);if(t.geometryFormat===GeometryFormat.XYZ){if(!r)return["","",""];if(!f(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(!f(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(!f(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 h(r)]:[""]:t.geometryFormat===GeometryFormat.GEO_JSON?r?[JSON.stringify(await O(r))]:[""]:[]}async function K(e,t){return e?.spatialReference&&!e.spatialReference.equals(t)&&t?(await w([e],t))[0]:e}function V(e,t){const r=[t.delimiter,_,"\r","\n",t.rowDelimiter];if(t.alwaysQuote||r.some((t=>e.includes(t)))){const t=e.replace(new RegExp(_,"g"),`${_}${_}`);return`${_}${t}${_}`}return e}function q(e,t){if(null==e)return"";if(!t.useFormattedValues){if("number"==typeof e){const r=t.numberFormat||A.ROUND_TRIP;return b(r,e)}if(e instanceof Date)return"timestamp"===t.dateFormat?e.getTime().toString():c({format:t.dateFormat,timeZone:"UTC"},e)}let r=e.toString();return t.escapeFormulaChars&&(r=te(r)),r}function Q(e,t,r){if(r.useFormattedValues||ee(e,t))return e.presentableAttributes.get(t)??e.attributes.get(t);if("date"===e.schema.findFieldByName(t)?.type){const r=s(e.attributes.get(t));if(!isNaN(r.getTime()))return r}return e.attributes.get(t)??e.presentableAttributes.get(t)}function ee(e,t){return!!E(t,e.schema.typeIdField)||("coded-value"===e.type?.domains?.[t]?.type||"coded-value"===e.schema.findFieldByName(t)?.domain?.type)}function te(e){for(const t of I)if(e.startsWith(t))return`\t${e}`;return e}function re(e,t,r){const o=e.startsWith(_),n=e.endsWith(_);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(_.length,e.length-_.length):e;let i=-1;return oe(a,_,((e,o)=>{if(o===a.length)return!0;if(i<0){if(o!==a.length)return i=o,!0}else if(o===i+_.length)return i=-1,!0;throw new Error(`Detected invalid CSV: Non-escaped quote for value at row:${t} column:${r}`)})),a.replace(new RegExp(`${_}${_}`,"g"),_)}function oe(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(_)?(n=!n,t+=_.length):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 ne(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 ae(e,t){const r=await T(JSON.parse(e));return r.spatialReference=t,r}async function ie(e,t){const r=await F(e);return r.spatialReference=t,r}function se(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 ce(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 me(e,t,r){return"inv"===t?"string"==typeof e?parseFloat(e.replaceAll(",","")):e:D({locale:t,format:r},e)}async function le(e,t,r){const o=r?e.slice(1):e;if(r){const r=se(e[0],GeometryFormat.ARCGIS_JSON);if(void 0!==r)for(const[e,n]of j){try{await ue(r[0],n,t,o)}catch(e){continue}return[e,[r[0]]]}const n=[GeometryFormat.XYZ,GeometryFormat.XY,GeometryFormat.LAT_LON];for(const t of n){const r=se(e[0],t);if(void 0!==r)return[t,r]}}for(const[e,r]of j){const n=await ce(o[0],r);if(void 0!==n){try{await ue(n,r,t,o)}catch(e){continue}return[e,[n]]}}return[GeometryFormat.NONE,[]]}async function ue(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 fe(e,t,r){let o=!1,n=!0,a=!0,i=!0;const c=new Set,{data:l,includeHeaderRow:f,dateFormat:d,primaryKeyField:p,locale:y}=e,g=f?l[0]:[],w=f?l.slice(1):l;for(const e of w){const r=e[t];r?.raw&&(c.add(r.raw),o=!0,n&&(n=G(r.raw,y)||Number.isNaN(r.raw)),a&&(a=r.raw instanceof Date||s(d||m,r.raw)!==u),i&&(i=s(d||P,r.formatted)!==u))}const h=c.size===w.length;return p&&g[t]?.raw===p||r&&o&&h&&n?"esriFieldTypeOID":o&&i?"esriFieldTypeDate":o&&n?"esriFieldTypeDouble":o&&a?"esriFieldTypeDate":"esriFieldTypeString"}async function de(e,t,r){const{escapeFormulaChars:o,locale:n,numberFormat:a,dateFormat:i}=r;if("esriFieldTypeDouble"===t.type||"esriFieldTypeOID"===t.type)return"number"==typeof e?e:e?me(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:s({locale:n,format:i},e).getTime()}const c=e?.toString()??"";if(o&&c.startsWith("\t"))for(const e of I)if(c.length>1&&c.charAt(1)===e)return c.substring(1);return c}function pe(e){switch(e){case l.DATE_SHORT:return"dd/MM/yyyy";case l.DATE_LONG:return"MMMM d, yyyy";case l.TIME_SHORT:return"h:mm AM/PM";case l.TIME_LONG:return"h:mm:ss AM/PM";case l.DATE_TIME_SHORT:case l.DEFAULT:return"MMM d yyyy h:mm AM/PM";case l.DATE_TIME_LONG:return"MMMM d yyyy h:mm AM/PM";case l.FULL:return"dddd, MMMM d yyyy h:mm AM/PM";case l.ISO_8601:case l.ROUND_TRIP:return'yyyy-MM-dd"T"HH:mm:ss';default:{const t=e.replace(/tt/g,"AM/PM");return t.includes("z")&&$().warn("Warning: Excel will not recognize timezone format 'z', 'zz', or 'zzz'"),t.includes("h")&&!t.includes("AM/PM")&&$().warn("Warning: Excel will interpret 'h' as 'H' if the format does not have an AM/PM designator"),t}}}function ye(e){switch(e){case A.ACCOUNTING:return'_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)';case A.CURRENCY:return'"$"#,##0.00';case A.FIXED_POINT:case A.DEFAULT:return"0.0000";case A.NUMBER:return"#,##0.0000";case A.PERCENT:return"0%";case A.ROUND_TRIP:return"0.00000";default:return e}}function ge(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}let r=e.toString();return t.escapeFormulaChars&&(r=te(r)),r}function we(e,t){return 3===e.length&&!t.hasZ&&t.hasM?[e[0],e[1],void 0,e[2]]:e}function he(e,t){return e.map((e=>we(e,t)))}function Fe(e,t){return e.map((e=>he(e,t)))}function Ne(e,t,r){switch(t){case U.NUMBER:return e instanceof Date?e.getTime():D(e);case U.STRING:return e instanceof Date?c({format:r.dateFormat??l.ROUND_TRIP,timeZone:"UTC"},e):"number"==typeof e?b(r.numberFormat??A.DEFAULT,e):e.toString();case U.BOOLEAN:return!!e;case U.DATE:return s(e);default:return e.toString()}}
|