12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import"../geometry.js";import e from"../core/Error.js";import r from"../core/Logger.js";import{isSome as t}from"../core/maybe.js";import a from"../geometry/SpatialReference.js";const s=r.getLogger("esri.support.arcadeOnDemand");let c;function i(){return c||(c=(async()=>{const e=await import("./arcadeUtils.js");return{arcade:e.arcade,arcadeUtils:e,Dictionary:e.Dictionary,Feature:e.arcadeFeature}})()),c}const n=(e,r,t)=>p.create(e,r,t,null,["$feature"]),o=(e,r,t)=>p.create(e,r,t,null,["$feature","$view"]),l=o,u=(e,r,t,a)=>p.create(e,r,t,a,["$feature","$view"]);class p{constructor(e,r,t,a,s,c,i,n){this.script=e,this.evaluate=s;const o=Array.isArray(i)?i:i.fields;this.fields=o,this._syntaxTree=a,this._arcade=r,this._arcadeDictionary=t,this._arcadeFeature=c,this._spatialReference=n,this._referencesGeometry=r.scriptTouchesGeometry(this._syntaxTree),this._referencesScale=this._arcade.referencesMember(this._syntaxTree,"scale")}static async create(r,c,n,o,l,u){const{arcade:d,Feature:m,Dictionary:f}=await i(),y=a.fromJSON(c);let h=null;try{h=d.parseScript(r,u)}catch(R){return s.error(new e("arcade-bad-expression","Failed to parse arcade script",{script:r,error:R})),null}const _=l.reduce(((e,r)=>({...e,[r]:null})),{});let w=null;t(o)&&(w=new f(o),w.immutable=!0,_.$config=null);const F=d.scriptUsesGeometryEngine(h),g=F&&d.enableGeometrySupport(),S=d.scriptUsesFeatureSet(h)&&d.enableFeatureSetSupport(),b=d.scriptIsAsync(h),x=b&&d.enableAsyncSupport(),$={vars:_,spatialReference:y,useAsync:!!x};await Promise.all([g,S,x]);const v=new Set;await d.loadDependentModules(v,h,null,b,F);const D=new f;D.immutable=!1,D.setField("scale",0);const j=d.compileScript(h,$),G=e=>("$view"in e&&e.$view&&(D.setField("scale",e.$view.scale),e.$view=D),w&&(e.$config=w),j({vars:e,spatialReference:y}));return new p(r,d,f,h,G,new m,n,y)}repurposeFeature(e){return e.geometry&&!e.geometry.spatialReference&&(e.geometry.spatialReference=this._spatialReference),this._arcadeFeature.repurposeFromGraphicLikeObject(e.geometry,e.attributes,{fields:this.fields}),this._arcadeFeature}createDictionary(){return new this._arcadeDictionary}referencesMember(e){return this._arcade.referencesMember(this._syntaxTree,e)}referencesFunction(e){return this._arcade.referencesFunction(this._syntaxTree,e)}referencesGeometry(){return this._referencesGeometry}referencesScale(){return this._referencesScale}extractFieldLiterals(){return this._arcade.extractExpectedFieldLiterals(this._syntaxTree)}}export{p as ArcadeExpression,u as createDictionaryExpression,n as createLabelExpression,o as createRendererExpression,l as createVVExpression,i as loadArcade};
|