labelFormatUtils-UVCDII77.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {
  2. _,
  3. x
  4. } from "./chunk-7O56JPWQ.js";
  5. import {
  6. L,
  7. S,
  8. m
  9. } from "./chunk-PIGRDDRG.js";
  10. import {
  11. B
  12. } from "./chunk-WZQZRKNH.js";
  13. import {
  14. s as s3
  15. } from "./chunk-LRDX4TO7.js";
  16. import "./chunk-UXF37FQ4.js";
  17. import "./chunk-ZOEK6QHJ.js";
  18. import "./chunk-2Z6LERTI.js";
  19. import "./chunk-OWVBLVP3.js";
  20. import "./chunk-XH7RUGVZ.js";
  21. import "./chunk-PDKDCAAD.js";
  22. import "./chunk-ECW2QABR.js";
  23. import "./chunk-GCDJLKH4.js";
  24. import "./chunk-MRJEICT6.js";
  25. import "./chunk-Y3WMVFTW.js";
  26. import "./chunk-SAS7RONY.js";
  27. import "./chunk-WSRBH7BF.js";
  28. import "./chunk-IHXECKQQ.js";
  29. import "./chunk-ULGDPLM2.js";
  30. import {
  31. s,
  32. s3 as s2
  33. } from "./chunk-EMJ4ZSM2.js";
  34. import "./chunk-IKP3YN53.js";
  35. import "./chunk-GZT4BVFP.js";
  36. import "./chunk-A5ICIBVI.js";
  37. // node_modules/@arcgis/core/layers/support/labelFormatUtils.js
  38. var s4 = s.getLogger("esri.layers.support.labelFormatUtils");
  39. var c = { type: "simple", evaluate: () => null };
  40. var f = { getAttribute: (e, r) => e.field(r) };
  41. async function p(r, t, a) {
  42. if (!r || !r.symbol)
  43. return c;
  44. const n = r.where, o = x(r), p2 = n ? await import("./WhereClause-3WNNGKYX.js") : null;
  45. let m2;
  46. if (o.type === "arcade") {
  47. const r2 = await s3(o.expression, a, t);
  48. m2 = { type: "arcade", evaluate(t2) {
  49. try {
  50. const e = r2.evaluate({ $feature: "attributes" in t2 ? r2.repurposeFeature(t2) : t2 });
  51. if (e != null)
  52. return e.toString();
  53. } catch (a2) {
  54. s4.error(new s2("arcade-expression-error", "Encountered an error when evaluating label expression for feature", { feature: t2, expression: o }));
  55. }
  56. return null;
  57. }, needsHydrationToEvaluate: () => _(o.expression) == null };
  58. } else
  59. m2 = { type: "simple", evaluate: (e) => o.expression.replace(/{[^}]*}/g, (r2) => {
  60. const a2 = r2.slice(1, -1), n2 = t.get(a2);
  61. if (!n2)
  62. return r2;
  63. let o2 = null;
  64. if ("attributes" in e) {
  65. e && e.attributes && (o2 = e.attributes[n2.name]);
  66. } else
  67. o2 = e.field(n2.name);
  68. return o2 == null ? "" : d(o2, n2);
  69. }) };
  70. if (n) {
  71. let r2;
  72. try {
  73. r2 = p2.WhereClause.create(n, t);
  74. } catch (g) {
  75. return s4.error(new s2("bad-where-clause", "Encountered an error when evaluating where clause, ignoring", { where: n, error: g })), c;
  76. }
  77. const a2 = m2.evaluate;
  78. m2.evaluate = (t2) => {
  79. const o2 = "attributes" in t2 ? void 0 : f;
  80. try {
  81. if (r2.testFeature(t2, o2))
  82. return a2(t2);
  83. } catch (g) {
  84. s4.error(new s2("bad-where-clause", "Encountered an error when evaluating where clause for feature", { where: n, feature: t2, error: g }));
  85. }
  86. return null;
  87. };
  88. }
  89. return m2;
  90. }
  91. function d(e, r) {
  92. if (e == null)
  93. return "";
  94. const l = r.domain;
  95. if (l) {
  96. if (l.type === "codedValue" || l.type === "coded-value") {
  97. const r2 = e;
  98. for (const e2 of l.codedValues)
  99. if (e2.code === r2)
  100. return e2.name;
  101. } else if (l.type === "range") {
  102. const r2 = +e, t = "range" in l ? l.range[0] : l.minValue, a = "range" in l ? l.range[1] : l.maxValue;
  103. if (t <= r2 && r2 <= a)
  104. return l.name;
  105. }
  106. }
  107. let i = e;
  108. return r.type === "date" || r.type === "esriFieldTypeDate" ? i = L(i, S("short-date")) : B(r) && (i = m(+i)), i || "";
  109. }
  110. export {
  111. p as createLabelFunction,
  112. d as formatField
  113. };
  114. //# sourceMappingURL=labelFormatUtils-UVCDII77.js.map