chunk-MPWGHCZG.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import {
  2. e
  3. } from "./chunk-FTI5VP6T.js";
  4. import {
  5. d
  6. } from "./chunk-JFNNSBWL.js";
  7. import {
  8. l
  9. } from "./chunk-7XXXCK2A.js";
  10. import {
  11. a,
  12. n
  13. } from "./chunk-LRDX4TO7.js";
  14. import {
  15. U
  16. } from "./chunk-VNFRAYHO.js";
  17. import {
  18. g
  19. } from "./chunk-ULGDPLM2.js";
  20. import {
  21. s,
  22. s3 as s2
  23. } from "./chunk-EMJ4ZSM2.js";
  24. import {
  25. c
  26. } from "./chunk-IKP3YN53.js";
  27. import {
  28. r
  29. } from "./chunk-GZT4BVFP.js";
  30. // node_modules/@arcgis/core/renderers/support/DictionaryLoader.js
  31. var f = s.getLogger("esri.renderers.support.DictionaryLoader");
  32. var h = { type: "CIMSimpleLineCallout", lineSymbol: { type: "CIMLineSymbol", symbolLayers: [{ type: "CIMSolidStroke", width: 0.5, color: [0, 0, 0, 255] }] } };
  33. var y = class {
  34. constructor(e2, t, s3) {
  35. this.config = null, this.fieldMap = null, this.url = null, this._ongoingRequests = new Map(), this._symbolCache = new e(100), this.url = e2, this.config = t, this.fieldMap = s3;
  36. }
  37. getSymbolFields() {
  38. return this._symbolFields;
  39. }
  40. async getSymbolAsync(t, s3) {
  41. let o;
  42. this._dictionaryPromise || (this._dictionaryPromise = this.fetchResources(s3));
  43. try {
  44. o = await this._dictionaryPromise;
  45. } catch (d2) {
  46. if (g(d2))
  47. return this._dictionaryPromise = null, null;
  48. }
  49. const i = {};
  50. if (this.fieldMap)
  51. for (const e2 of this._symbolFields) {
  52. const s4 = this.fieldMap[e2];
  53. if (s4 && t.attributes[s4] != null) {
  54. const o2 = "" + t.attributes[s4];
  55. i[e2] = o2;
  56. } else
  57. i[e2] = "";
  58. }
  59. const a2 = o(i, s3);
  60. if (!a2 || typeof a2 != "string")
  61. return null;
  62. const c2 = c(a2).toString(), m = this._symbolCache.get(c2);
  63. if (m)
  64. return m.catch(() => {
  65. this._symbolCache.pop(c2);
  66. }), m;
  67. const f2 = a2.split(";"), h2 = [], y2 = [];
  68. for (const r2 of f2)
  69. if (r2)
  70. if (r2.includes("po:")) {
  71. const t2 = r2.substr(3).split("|");
  72. if (t2.length === 3) {
  73. const s4 = t2[0], o2 = t2[1];
  74. let i2 = t2[2];
  75. if (o2 === "DashTemplate")
  76. i2 = i2.split(" ").map((e2) => Number(e2));
  77. else if (o2 === "Color") {
  78. const t3 = new l(i2).toRgba();
  79. i2 = [t3[0], t3[1], t3[2], 255 * t3[3]];
  80. } else
  81. i2 = Number(i2);
  82. y2.push({ primitiveName: s4, propertyName: o2, value: i2 });
  83. }
  84. } else if (r2.includes("|")) {
  85. for (const e2 of r2.split("|"))
  86. if (this._itemNames.has(e2)) {
  87. h2.push(e2);
  88. break;
  89. }
  90. } else
  91. this._itemNames.has(r2) && h2.push(r2);
  92. const u2 = !r(t.geometry) || !t.geometry.hasZ && t.geometry.type === "point", p2 = this._cimPartsToCIMSymbol(h2, y2, u2, s3);
  93. return this._symbolCache.put(c2, p2, 1), p2;
  94. }
  95. async fetchResources(e2) {
  96. if (this._dictionaryPromise)
  97. return this._dictionaryPromise;
  98. if (!this.url)
  99. return void f.error("no valid URL!");
  100. const o = U(this.url + "/resources/styles/dictionary-info.json", { responseType: "json", query: { f: "json" }, signal: r(e2) ? e2.signal : null }), [{ data: i }] = await Promise.all([o, a()]);
  101. if (!i)
  102. throw this._dictionaryPromise = null, new s2("esri.renderers.DictionaryRenderer", "Bad dictionary data!");
  103. const n2 = i.expression, l2 = i.authoringInfo;
  104. this._refSymbolUrlTemplate = this.url + "/" + i.cimRefTemplateUrl, this._itemNames = new Set(i.itemsNames), this._symbolFields = l2.symbol;
  105. const m = {};
  106. if (this.config) {
  107. const e3 = this.config;
  108. for (const t in e3)
  109. m[t] = e3[t];
  110. }
  111. if (l2.configuration)
  112. for (const t of l2.configuration)
  113. m.hasOwnProperty(t.name) || (m[t.name] = t.value);
  114. const h2 = [];
  115. if (r(e2) && e2.fields && this.fieldMap)
  116. for (const t of this._symbolFields) {
  117. const s3 = this.fieldMap[t], o2 = e2.fields.filter((e3) => e3.name === s3);
  118. o2.length > 0 && h2.push({ ...o2[0], name: t });
  119. }
  120. return this._dictionaryPromise = n(n2, r(e2) ? e2.spatialReference : null, h2, m).then((e3) => {
  121. const t = { scale: 0 };
  122. return (s3, o2) => {
  123. const i2 = e3.repurposeFeature({ geometry: null, attributes: s3 });
  124. return t.scale = r(o2) ? o2.scale : void 0, e3.evaluate({ $feature: i2, $view: t });
  125. };
  126. }).catch((e3) => (f.error("Creating dictinoary expression failed:", e3), null)), this._dictionaryPromise;
  127. }
  128. async _cimPartsToCIMSymbol(e2, t, s3, o) {
  129. const i = new Array(e2.length);
  130. for (let l2 = 0; l2 < e2.length; l2++)
  131. i[l2] = this._getSymbolPart(e2[l2], o);
  132. const r2 = await Promise.all(i), n2 = this.fieldMap;
  133. for (const l2 of r2)
  134. u(l2, n2);
  135. return new d({ data: this._combineSymbolParts(r2, t, s3) });
  136. }
  137. async _getSymbolPart(e2, s3) {
  138. if (this._ongoingRequests.has(e2))
  139. return this._ongoingRequests.get(e2).then((e3) => e3.data);
  140. const o = this._refSymbolUrlTemplate.replace(/\{itemName\}/gi, e2), i = U(o, { responseType: "json", query: { f: "json" }, ...s3 });
  141. this._ongoingRequests.set(e2, i);
  142. try {
  143. return (await i).data;
  144. } catch (r2) {
  145. throw this._ongoingRequests.delete(e2), r2;
  146. }
  147. }
  148. _combineSymbolParts(e2, t, s3) {
  149. if (!e2 || e2.length === 0)
  150. return null;
  151. const o = { ...e2[0] };
  152. if (e2.length > 1) {
  153. o.symbolLayers = [];
  154. for (const t2 of e2) {
  155. const e3 = t2;
  156. o.symbolLayers.unshift(...e3.symbolLayers);
  157. }
  158. }
  159. return s3 && (o.callout = h), { type: "CIMSymbolReference", symbol: o, primitiveOverrides: t };
  160. }
  161. };
  162. function u(e2, t) {
  163. if (!e2)
  164. return;
  165. const s3 = e2.symbolLayers;
  166. if (!s3)
  167. return;
  168. let o = s3.length;
  169. for (; o--; ) {
  170. const e3 = s3[o];
  171. if (e3 && e3.enable !== false && e3.type === "CIMVectorMarker")
  172. p(e3, t);
  173. }
  174. }
  175. function p(e2, t) {
  176. const s3 = e2.markerGraphics;
  177. if (s3)
  178. for (const o of s3) {
  179. if (!o)
  180. continue;
  181. const e3 = o.symbol;
  182. if (e3)
  183. switch (e3.type) {
  184. case "CIMPointSymbol":
  185. case "CIMLineSymbol":
  186. case "CIMPolygonSymbol":
  187. u(e3, t);
  188. break;
  189. case "CIMTextSymbol":
  190. e3.fieldMap = t;
  191. }
  192. }
  193. }
  194. export {
  195. y
  196. };
  197. //# sourceMappingURL=chunk-MPWGHCZG.js.map