UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.41 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../../Graphic.js";import i from"../../../core/Accessor.js";import{createTask as s}from"../../../core/asyncUtils.js";import{abortMaybe as o}from"../../../core/maybe.js";import{throwIfAborted as a}from"../../../core/promiseUtils.js";import{watch as r,initial as n,when as l}from"../../../core/reactiveUtils.js";import{throttle as p}from"../../../core/throttle.js";import{property as c,subclass as h}from"../../../core/accessorSupport/decorators.js";import m from"../../../geometry/Point.js";import{MediaContent as d,TextContent as u,FieldsContent as f}from"../../../popup/content.js";import v from"../../../popup/ElementExpressionInfo.js";import _ from"../FeatureContent/FeatureContentViewModel.js";import y from"../FeatureFields/FeatureFieldsViewModel.js";import w from"../FeatureMedia/FeatureMediaViewModel.js";import{compileExpression as T}from"../support/arcadeFeatureUtils.js";const k=1;let E=class extends i{constructor(e){super(e),this._compileTask=null,this._evaluateTask=null,this.expressionInfo=null,this.graphic=null,this.contentElementViewModel=null,this.interceptor=null,this.location=null,this.view=null,this._createVM=()=>{const e=this.contentElement?.type;this.contentElementViewModel?.destroy();const t="fields"===e?new y:"media"===e?new w:"text"===e?new _:null;this._set("contentElementViewModel",t)},this._compileThrottled=p(this._startCompile,()=>this.notifyChange("state"),k,this),this._evaluateThrottled=p(this._startEvaluate,()=>this.notifyChange("state"),k,this),this.addHandles([r(()=>[this.expressionInfo,this.graphic],()=>this._compileThrottled(),n),r(()=>[this.contentElement],()=>this._createVM(),n),l(()=>{if(!this._compileTask?.finished)return null;const e=this._compileTask.value,t=e?.dependencies;return[e,this.spatialReference,this.map,this.view,t?.has("view-scale")?this.view?.scale:null,t?.has("view-time-extent")?this.view?.timeExtent?.start:null,t?.has("view-time-extent")?this.view?.timeExtent?.end:null]},([e])=>this._evaluateThrottled(e))])}initialize(){this.addHandles([this._compileThrottled,this._evaluateThrottled])}destroy(){this._compileTask=o(this._compileTask),this._evaluateTask=o(this._evaluateTask),this.contentElementViewModel?.destroy(),this._set("contentElementViewModel",null)}get contentElement(){return this._evaluateTask?.value}get spatialReference(){return this.view?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){const{contentElement:e,contentElementViewModel:t}=this;return this._compileThrottled.hasPendingUpdates()||this._evaluateThrottled.hasPendingUpdates()||!this._compileTask?.finished||!this._evaluateTask?.finished?"loading":e||t?"ready":"disabled"}get map(){return this.view?.map??null}set map(e){this._override("map",e)}_startCompile(){this._evaluateTask=o(this._evaluateTask),this._compileTask=o(this._compileTask),this._compileTask=s(async e=>{const{expressionInfo:t,graphic:i}=this,s=t?.expression;if(!s||!i)return null;const o=await T({expression:s,graphic:i});return a(e),o})}_startEvaluate(e){this._evaluateTask=o(this._evaluateTask),this._evaluateTask=s(async t=>{const{graphic:i}=this;if(!e||!i)return null;const{interceptor:s,spatialReference:o,map:r,location:n,view:l}=this,p=await e.evaluate({graphic:i,interceptor:s,location:n,map:r,options:{signal:t},spatialReference:o,view:l});a(t);const c=p;if(!c||"esri.arcade.Dictionary"!==c.declaredClass)return null;const h=await c.castAsJsonAsync(t);a(t);const m=h?.type,v="media"===m?d.fromJSON(h):"text"===m?u.fromJSON(h):"fields"===m?f.fromJSON(h):null;return"media"===v.type&&!v.mediaInfos||"fields"===v.type&&!v.fieldInfos||"text"===v.type&&!v.text?null:v})}};e([c()],E.prototype,"_compileTask",void 0),e([c()],E.prototype,"_evaluateTask",void 0),e([c({type:v})],E.prototype,"expressionInfo",void 0),e([c({type:t})],E.prototype,"graphic",void 0),e([c({readOnly:!0})],E.prototype,"contentElement",null),e([c({readOnly:!0})],E.prototype,"contentElementViewModel",void 0),e([c()],E.prototype,"interceptor",void 0),e([c({type:m})],E.prototype,"location",void 0),e([c()],E.prototype,"spatialReference",null),e([c({readOnly:!0})],E.prototype,"state",null),e([c()],E.prototype,"map",null),e([c()],E.prototype,"view",void 0),E=e([h("esri.widgets.Feature.FeatureExpression.FeatureExpressionViewModel")],E);export{E as default};