labelFormatUtils.3dd0946d.js 2.0 KB

1
  1. import{s as y,kx as m,al as h,ky as v,t as w,g as d,kz as b,gv as x,kA as _,kB as k,kC as E}from"./index.a33cbbbf.js";const p=y.getLogger("esri.layers.support.labelFormatUtils"),g={type:"simple",evaluate:()=>null},F={getAttribute:(a,u)=>a.field(u)};async function A(a,u,e){if(!a||!a.symbol)return g;const n=a.where,l=m(a),o=n?await h(()=>import("./WhereClause.8cdbfcdb.js"),["assets/WhereClause.8cdbfcdb.js","assets/index.a33cbbbf.js","assets/index.865a2a37.css"]):null;let i;if(l.type==="arcade"){const r=await v(l.expression,e,u);if(w(r))return g;i={type:"arcade",evaluate(s){try{const t=r.evaluate({$feature:"attributes"in s?r.repurposeFeature(s):s});if(t!=null)return t.toString()}catch{p.error(new d("arcade-expression-error","Encountered an error when evaluating label expression for feature",{feature:s,expression:l}))}return null},needsHydrationToEvaluate:()=>k(l.expression)==null}}else i={type:"simple",evaluate:r=>l.expression.replace(/{[^}]*}/g,s=>{const t=s.slice(1,-1),c=u.get(t);if(!c)return s;let f=null;return"attributes"in r?r&&r.attributes&&(f=r.attributes[c.name]):f=r.field(c.name),f==null?"":V(f,c)})};if(n){let r;try{r=o.WhereClause.create(n,u)}catch(t){return p.error(new d("bad-where-clause","Encountered an error when evaluating where clause, ignoring",{where:n,error:t})),g}const s=i.evaluate;i.evaluate=t=>{const c="attributes"in t?void 0:F;try{if(r.testFeature(t,c))return s(t)}catch(f){p.error(new d("bad-where-clause","Encountered an error when evaluating where clause for feature",{where:n,feature:t,error:f}))}return null}}return i}function V(a,u){if(a==null)return"";const e=u.domain;if(e){if(e.type==="codedValue"||e.type==="coded-value"){const l=a;for(const o of e.codedValues)if(o.code===l)return o.name}else if(e.type==="range"){const l=+a,o="range"in e?e.range[0]:e.minValue,i="range"in e?e.range[1]:e.maxValue;if(o<=l&&l<=i)return e.name}}let n=a;return u.type==="date"||u.type==="esriFieldTypeDate"?n=b(n,E("short-date")):x(u)&&(n=_(+n)),n||""}export{A as createLabelFunction,V as formatField};