@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.22 kB
JavaScript
import has from"../../../../core/has.js";import{isNone as e,isSome as s}from"../../../../core/maybe.js";import{diff as t,hasDiff as i}from"../../../../core/accessorSupport/diffUtils.js";import{createRendererExpression as r}from"../../../../support/arcadeOnDemand.js";import a from"../../arcade/callExpressionWithCursor.js";const o=import("../../../../layers/support/labelFormatUtils.js");class c{constructor(e,s){this._canCacheExpressionValue=!1,this._sourceInfo=e,this._storage=s,this._bitsets={computed:s.getBitset(s.createBitset())}}get storage(){return this._storage}invalidate(){this._bitsets.computed.clear()}async updateSchema(r,a){const o=t(this._schema,a);if(this._schema=a,!a||e(o)||!i(o,"attributes"))return;has("esri-2d-update-debug")&&console.debug("Applying Update - Store:",o),this._bitsets.computed.clear(),r.targets[a.name]=!0;const c=a.attributes,n=[],p=[];for(const e in c){const s=c[e];switch(s.type){case"field":break;case"expression":n.push(this._createArcadeComputedField(s));break;case"label-expression":n.push(this._createLabelArcadeComputedField(s));break;case"statistic":p.push(s)}}this._computedFields=await Promise.all(n),this._canCacheExpressionValue=!this._computedFields.some((e=>"expression"===e.type&&s(e.expression)&&e.expression.referencesScale())),this._statisticFields=p}setComputedAttributes(e,s,t,i){const r=this._bitsets.computed;if(!this._canCacheExpressionValue||!r.has(t)){r.set(t);for(const r of this._computedFields){const a=this._evaluateField(s,r,i);switch(r.resultType){case"numeric":e.setComputedNumericAtIndex(t,r.fieldIndex,a);break;case"string":e.setComputedStringAtIndex(t,r.fieldIndex,a)}}}}async _createArcadeComputedField(e){const s=this._sourceInfo.spatialReference,t=this._sourceInfo.fieldsIndex;return{...e,expression:await r(e.valueExpression,s,t)}}async _createLabelArcadeComputedField(e){const s=this._sourceInfo.spatialReference,t=this._sourceInfo.fieldsIndex,{createLabelFunction:i}=await o,r=await i(e.label,t,s);return{...e,builder:r}}_evaluateField(e,s,t){switch(s.type){case"label-expression":{const t=e.readArcadeFeature();return s.builder.evaluate(t)||""}case"expression":{const{expression:i}=s;return a(i,e,{$view:{scale:t}})}}}}export{c as Store2D};