CSVSourceWorker-3RM7DFJI.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. import {
  2. a as a2,
  3. u as u2
  4. } from "./chunk-4D6PVVFX.js";
  5. import {
  6. u
  7. } from "./chunk-5FHVUYVE.js";
  8. import {
  9. Y
  10. } from "./chunk-NP2BYFXT.js";
  11. import "./chunk-6H5PP7QI.js";
  12. import "./chunk-HSPVIAVJ.js";
  13. import "./chunk-XIEPNAEI.js";
  14. import {
  15. f
  16. } from "./chunk-M5BTTMP6.js";
  17. import "./chunk-WQJRLXWG.js";
  18. import "./chunk-ETWBEEKL.js";
  19. import {
  20. t as t2
  21. } from "./chunk-XZA4MVET.js";
  22. import "./chunk-4GGRJYTB.js";
  23. import "./chunk-D5GG5NVO.js";
  24. import "./chunk-USORKAIZ.js";
  25. import "./chunk-Q34L5KZA.js";
  26. import "./chunk-ROWZMUVJ.js";
  27. import "./chunk-7IKYLNB5.js";
  28. import "./chunk-P4UZNLD5.js";
  29. import "./chunk-FYNVVMWY.js";
  30. import "./chunk-Q52DVFYK.js";
  31. import {
  32. s as s3,
  33. t
  34. } from "./chunk-HBMVUVZX.js";
  35. import "./chunk-QOV6ITMI.js";
  36. import {
  37. ln
  38. } from "./chunk-DH2OBAUC.js";
  39. import "./chunk-TNLRDNTC.js";
  40. import {
  41. a
  42. } from "./chunk-3ZFH4KQV.js";
  43. import "./chunk-KUXNUNAI.js";
  44. import {
  45. d
  46. } from "./chunk-KMAHKQ2G.js";
  47. import "./chunk-522WBHUO.js";
  48. import "./chunk-WNCU6BFU.js";
  49. import "./chunk-EOSZHC5H.js";
  50. import "./chunk-C43UE3Z5.js";
  51. import "./chunk-NE3ESGA6.js";
  52. import "./chunk-YIS6BAC3.js";
  53. import "./chunk-7XXXCK2A.js";
  54. import "./chunk-7ZIDBK7B.js";
  55. import {
  56. P
  57. } from "./chunk-WZQZRKNH.js";
  58. import "./chunk-LRDX4TO7.js";
  59. import "./chunk-WDLTDV2L.js";
  60. import "./chunk-TERAW6FT.js";
  61. import "./chunk-N2663GRX.js";
  62. import "./chunk-O4FY3ITT.js";
  63. import "./chunk-JXW4QTJA.js";
  64. import "./chunk-UXF37FQ4.js";
  65. import "./chunk-ZOEK6QHJ.js";
  66. import "./chunk-XNLG7T2T.js";
  67. import "./chunk-IR4PV7VK.js";
  68. import "./chunk-2Z6LERTI.js";
  69. import "./chunk-OWVBLVP3.js";
  70. import "./chunk-MXB2XLKV.js";
  71. import "./chunk-XH7RUGVZ.js";
  72. import "./chunk-ALDCDSPV.js";
  73. import "./chunk-DT6EAZQ5.js";
  74. import "./chunk-HNOZUNJ4.js";
  75. import {
  76. U
  77. } from "./chunk-VNFRAYHO.js";
  78. import "./chunk-R5IG2D6H.js";
  79. import {
  80. Ut,
  81. j
  82. } from "./chunk-VBRY5KJM.js";
  83. import "./chunk-PDKDCAAD.js";
  84. import {
  85. y
  86. } from "./chunk-ECW2QABR.js";
  87. import "./chunk-GCDJLKH4.js";
  88. import {
  89. E,
  90. c,
  91. k,
  92. k2
  93. } from "./chunk-MRJEICT6.js";
  94. import "./chunk-Y3WMVFTW.js";
  95. import "./chunk-SAS7RONY.js";
  96. import "./chunk-WSRBH7BF.js";
  97. import "./chunk-IHXECKQQ.js";
  98. import {
  99. O,
  100. g
  101. } from "./chunk-ULGDPLM2.js";
  102. import {
  103. s,
  104. s3 as s2
  105. } from "./chunk-EMJ4ZSM2.js";
  106. import "./chunk-IKP3YN53.js";
  107. import "./chunk-GZT4BVFP.js";
  108. import "./chunk-A5ICIBVI.js";
  109. // node_modules/@arcgis/core/layers/graphics/sources/csv/csv.js
  110. var n = /^\s*"([\S\s]*)"\s*$/;
  111. var t3 = /""/g;
  112. var e = "\n";
  113. var o = [",", " ", ";", "|", " "];
  114. function* c2(n3, t4, e2) {
  115. let o3 = 0;
  116. for (; o3 <= n3.length; ) {
  117. const c3 = n3.indexOf(t4, o3), i3 = n3.substring(o3, c3 > -1 ? c3 : void 0);
  118. o3 += i3.length + t4.length, e2 && !i3.trim() || (yield i3);
  119. }
  120. }
  121. function i(n3) {
  122. const t4 = n3.includes("\r\n") ? "\r\n" : e;
  123. return c2(n3, t4, true);
  124. }
  125. function r(n3, t4) {
  126. return c2(n3, t4, false);
  127. }
  128. function f2(n3) {
  129. const t4 = n3.trim();
  130. let e2 = 0, c3 = "";
  131. for (const i3 of o) {
  132. const n4 = t4.split(i3).length;
  133. n4 > e2 && (e2 = n4, c3 = i3);
  134. }
  135. return c3 === "" ? null : c3;
  136. }
  137. function* l(o3, c3, i3, f3 = () => Object.create(null)) {
  138. let l3 = "", u4 = "", d3 = 0, g2 = f3(), x = 0;
  139. n:
  140. for (const h of o3) {
  141. const o4 = r(h, i3);
  142. for (const e2 of o4)
  143. if (l3 += u4 + e2, u4 = "", d3 += s4(e2), d3 % 2 == 0) {
  144. if (d3 > 0) {
  145. const e3 = n.exec(l3);
  146. if (!e3) {
  147. g2 = f3(), x = 0, l3 = "", d3 = 0;
  148. continue n;
  149. }
  150. g2[c3[x]] = e3[1].replace(t3, '"'), x++;
  151. } else
  152. g2[c3[x]] = l3, x++;
  153. l3 = "", d3 = 0;
  154. } else
  155. u4 = i3;
  156. d3 === 0 ? (yield g2, g2 = f3(), x = 0) : u4 = e;
  157. }
  158. }
  159. function s4(n3) {
  160. let t4 = 0, e2 = 0;
  161. for (e2 = n3.indexOf('"', e2); e2 >= 0; )
  162. t4++, e2 = n3.indexOf('"', e2 + 1);
  163. return t4;
  164. }
  165. // node_modules/@arcgis/core/layers/graphics/sources/support/inferenceUtils.js
  166. function r2(e2) {
  167. const t4 = e2.map((e3) => e3.toLowerCase());
  168. return { longitudeFieldName: e2[t4.indexOf(d2.find((e3) => t4.includes(e3)))], latitudeFieldName: e2[t4.indexOf(s5.find((e3) => t4.includes(e3)))] };
  169. }
  170. function n2(e2, r3, n3, l3) {
  171. const o3 = [], a4 = l(e2, n3, r3), u4 = [];
  172. for (const t4 of a4) {
  173. if (u4.length === 10)
  174. break;
  175. u4.push(t4);
  176. }
  177. for (const t4 of n3)
  178. if (t4 === l3.longitudeFieldName || t4 === l3.latitudeFieldName)
  179. o3.push({ name: t4, type: "esriFieldTypeDouble", alias: t4 });
  180. else {
  181. const e3 = i2(u4.map((e4) => e4[t4])), r4 = { name: t4, type: null, alias: t4 };
  182. switch (e3) {
  183. case "integer":
  184. r4.type = "esriFieldTypeInteger";
  185. break;
  186. case "double":
  187. r4.type = "esriFieldTypeDouble";
  188. break;
  189. case "date":
  190. r4.type = "esriFieldTypeDate", r4.length = 36;
  191. break;
  192. default:
  193. r4.type = "esriFieldTypeString", r4.length = 255;
  194. }
  195. o3.push(r4);
  196. }
  197. return o3;
  198. }
  199. function i2(e2) {
  200. if (!e2.length)
  201. return "string";
  202. const t4 = /[^+-.,0-9]/;
  203. return e2.map((e3) => {
  204. let r3 = false;
  205. if (e3 !== "") {
  206. if (t4.test(e3))
  207. r3 = true;
  208. else {
  209. let t5 = o2(e3);
  210. if (!isNaN(t5))
  211. return /[.,]/.test(e3) || !Number.isInteger(t5) || t5 > 214783647 || t5 < -214783648 ? "double" : "integer";
  212. if (e3.includes("E")) {
  213. if (t5 = Number(e3), !isNaN(t5))
  214. return "double";
  215. if (e3.includes(",")) {
  216. if (e3 = e3.replace(",", "."), t5 = Number(e3), !isNaN(t5))
  217. return "double";
  218. r3 = true;
  219. } else
  220. r3 = true;
  221. } else
  222. r3 = true;
  223. }
  224. if (r3) {
  225. if (!/^[-]?\d*[.,]?\d*$/.test(e3)) {
  226. return l2(new Date(e3), e3) ? "date" : "string";
  227. }
  228. return "string";
  229. }
  230. return "string";
  231. }
  232. }).reduce((e3, t5) => e3 === void 0 || e3 === t5 ? t5 : e3 === "string" || t5 === "string" ? "string" : e3 === "double" || t5 === "double" ? "double" : void 0);
  233. }
  234. function l2(e2, t4) {
  235. if (!e2 || Object.prototype.toString.call(e2) !== "[object Date]" || isNaN(e2.getTime()))
  236. return false;
  237. let r3 = true;
  238. if (!u3 && /\d+\W*$/.test(t4)) {
  239. const e3 = t4.match(/[a-zA-Z]{2,}/);
  240. if (e3) {
  241. let t5 = false, n3 = 0;
  242. for (; !t5 && n3 <= e3.length; )
  243. t5 = !a3.test(e3[n3]), n3++;
  244. r3 = !t5;
  245. }
  246. }
  247. return r3;
  248. }
  249. var o2 = function() {
  250. const t4 = a(), r3 = new RegExp("^" + t4.regexp + "$"), n3 = new RegExp("[" + t4.group + "\\s\\xa0]", "g"), i3 = t4.factor;
  251. return (e2) => {
  252. const l3 = r3.exec(e2);
  253. if (t4.factor = i3, !l3)
  254. return NaN;
  255. let o3 = l3[1];
  256. if (!l3[1]) {
  257. if (!l3[2])
  258. return NaN;
  259. o3 = l3[2], t4.factor *= -1;
  260. }
  261. return o3 = o3.replace(n3, "").replace(t4.decimal, "."), +o3 * t4.factor;
  262. };
  263. }();
  264. var a3 = /^((jan(uary)?)|(feb(ruary)?)|(mar(ch)?)|(apr(il)?)|(may)|(jun(e)?)|(jul(y)?)|(aug(ust)?)|(sep(tember)?)|(oct(ober)?)|(nov(ember)?)|(dec(ember)?)|(am)|(pm)|(gmt)|(utc))$/i;
  265. var u3 = Number.isNaN(new Date("technology 10").getTime());
  266. var s5 = ["lat", "latitude", "latitude83", "latdecdeg", "lat_dd", "y", "ycenter", "point-y"];
  267. var d2 = ["lon", "lng", "long", "longitude", "longitude83", "longdecdeg", "long_dd", "x", "xcenter", "point-x"];
  268. // node_modules/@arcgis/core/layers/graphics/sources/support/CSVSourceWorker.js
  269. var b = u2("esriGeometryPoint");
  270. var v = ["csv"];
  271. var D = [0, 0];
  272. var O2 = class {
  273. constructor(e2, t4) {
  274. this.x = e2, this.y = t4;
  275. }
  276. };
  277. var k3 = class {
  278. constructor() {
  279. this._queryEngine = null, this._snapshotFeatures = async (e2) => {
  280. const t4 = await this._fetch(e2);
  281. return this._createFeatures(t4);
  282. };
  283. }
  284. destroy() {
  285. this._queryEngine?.destroy(), this._queryEngine = null;
  286. }
  287. async load(e2, t4 = {}) {
  288. this.loadOptions = e2;
  289. const [i3] = await Promise.all([this._fetch(t4.signal), this._checkProjection(e2?.parsingOptions?.spatialReference)]), n3 = P2(i3, e2);
  290. this.locationInfo = n3.locationInfo, this.delimiter = n3.delimiter, this._queryEngine = this._createQueryEngine(n3);
  291. const r3 = await this._createFeatures(i3);
  292. if (this._queryEngine.featureStore.addMany(r3), n3.layerDefinition.extent = this._queryEngine.fullExtent, n3.layerDefinition.timeInfo) {
  293. const { start: e3, end: t5 } = this._queryEngine.timeExtent;
  294. n3.layerDefinition.timeInfo.timeExtent = [e3, t5];
  295. }
  296. return n3;
  297. }
  298. async applyEdits() {
  299. throw new s2("csv-layer:editing-not-supported", "applyEdits() is not supported on CSVLayer");
  300. }
  301. async queryFeatures(e2 = {}, t4 = {}) {
  302. return await this._waitSnapshotComplete(), this._queryEngine.executeQuery(e2, t4.signal);
  303. }
  304. async queryFeatureCount(e2 = {}, t4 = {}) {
  305. return await this._waitSnapshotComplete(), this._queryEngine.executeQueryForCount(e2, t4.signal);
  306. }
  307. async queryObjectIds(e2 = {}, t4 = {}) {
  308. return await this._waitSnapshotComplete(), this._queryEngine.executeQueryForIds(e2, t4.signal);
  309. }
  310. async queryExtent(e2 = {}, t4 = {}) {
  311. return await this._waitSnapshotComplete(), this._queryEngine.executeQueryForExtent(e2, t4.signal);
  312. }
  313. async querySnapping(e2, t4 = {}) {
  314. return await this._waitSnapshotComplete(), this._queryEngine.executeQueryForSnapping(e2, t4.signal);
  315. }
  316. async refresh(e2) {
  317. return this.loadOptions.customParameters = e2, this._snapshotTask?.abort(), this._snapshotTask = O(this._snapshotFeatures), this._snapshotTask.promise.then((e3) => {
  318. this._queryEngine.featureStore.clear(), e3 && this._queryEngine.featureStore.addMany(e3);
  319. }, (e3) => {
  320. this._queryEngine.featureStore.clear(), g(e3) || s.getLogger("esri.layers.CSVLayer").error(new s2("csv-layer:refresh", "An error occurred during refresh", { error: e3 }));
  321. }), await this._waitSnapshotComplete(), { extent: this._queryEngine.fullExtent, timeExtent: this._queryEngine.timeExtent };
  322. }
  323. async _waitSnapshotComplete() {
  324. if (this._snapshotTask && !this._snapshotTask.finished) {
  325. try {
  326. await this._snapshotTask.promise;
  327. } catch {
  328. }
  329. return this._waitSnapshotComplete();
  330. }
  331. }
  332. async _fetch(i3) {
  333. const { url: n3, customParameters: r3 } = this.loadOptions;
  334. if (!n3)
  335. throw new s2("csv-layer:invalid-source", "url not defined");
  336. const o3 = j(n3);
  337. return (await U(o3.path, { query: { ...o3.query, ...r3 }, responseType: "text", signal: i3 })).data;
  338. }
  339. _createQueryEngine(e2) {
  340. const { objectIdField: t4, fields: i3, extent: n3, timeInfo: r3 } = e2.layerDefinition, s6 = new u({ geometryType: "esriGeometryPoint", hasM: false, hasZ: false });
  341. return new Y({ fields: i3, geometryType: "esriGeometryPoint", hasM: false, hasZ: false, timeInfo: r3, objectIdField: t4, spatialReference: n3.spatialReference || { wkid: 4326 }, cacheSpatialQueries: true, featureStore: s6 });
  342. }
  343. async _createFeatures(e2) {
  344. const { latitudeFieldName: t4, longitudeFieldName: i3 } = this.locationInfo, { objectIdField: n3, fieldsIndex: r3, spatialReference: s6 } = this._queryEngine;
  345. let o3 = [];
  346. const u4 = [], y2 = r3.fields.filter((e3) => e3.name !== n3).map((e3) => e3.name);
  347. let h = 0;
  348. const g2 = i(e2);
  349. g2.next();
  350. const I = {};
  351. for (const a4 of r3.fields)
  352. if (a4.type !== "esriFieldTypeOID" && a4.type !== "esriFieldTypeGlobalID") {
  353. const e3 = P(a4);
  354. e3 !== void 0 && (I[a4.name] = e3);
  355. }
  356. const E2 = l(g2, y2, this.delimiter, a2(I, n3));
  357. for (const a4 of E2) {
  358. const e3 = this._parseCoordinateValue(a4[t4]), s7 = this._parseCoordinateValue(a4[i3]);
  359. if (s7 != null && e3 != null && !isNaN(e3) && !isNaN(s7)) {
  360. a4[t4] = e3, a4[i3] = s7;
  361. for (const e4 in a4)
  362. if (e4 !== t4 && e4 !== i3) {
  363. if (r3.isDateField(e4)) {
  364. const t5 = new Date(a4[e4]);
  365. a4[e4] = l2(t5, a4[e4]) ? t5.getTime() : null;
  366. } else if (r3.isNumericField(e4)) {
  367. const t5 = o2(a4[e4]);
  368. isNaN(t5) ? a4[e4] = null : a4[e4] = t5;
  369. }
  370. }
  371. a4[n3] = h, h++, o3.push(new O2(s7, e3)), u4.push(a4);
  372. }
  373. }
  374. if (!E({ wkid: 4326 }, s6))
  375. if (k(s6))
  376. for (const a4 of o3)
  377. [a4.x, a4.y] = y(a4.x, a4.y, D);
  378. else
  379. o3 = ln(t2, o3, k2.WGS84, s6, null, null);
  380. const N = [];
  381. for (let a4 = 0; a4 < o3.length; a4++) {
  382. const { x: e3, y: t5 } = o3[a4], i4 = u4[a4];
  383. i4[n3] = a4 + 1, N.push(new s3(new t([], [e3, t5]), i4, null, i4[n3]));
  384. }
  385. return N;
  386. }
  387. _parseCoordinateValue(e2) {
  388. if (e2 == null || e2 === "")
  389. return null;
  390. let t4 = o2(e2);
  391. return (isNaN(t4) || Math.abs(t4) > 181) && (t4 = parseFloat(e2)), t4;
  392. }
  393. async _checkProjection(e2) {
  394. try {
  395. await f(c, e2);
  396. } catch {
  397. throw new s2("csv-layer:projection-not-supported", "Projection not supported");
  398. }
  399. }
  400. };
  401. function P2(e2, i3) {
  402. const n3 = i3.parsingOptions || {}, r3 = { delimiter: n3.delimiter, layerDefinition: null, locationInfo: { latitudeFieldName: n3.latitudeField, longitudeFieldName: n3.longitudeField } }, s6 = i(e2);
  403. let a4 = s6.next().value;
  404. if (!a4)
  405. throw new s2("csv-layer:empty-csv", "CSV is empty", { csv: e2 });
  406. if (a4 = a4.trim(), !n3.delimiter) {
  407. const e3 = f2(a4);
  408. if (!e3)
  409. throw new s2("csv-layer:invalid-delimiter", "Unable to detect the delimiter from CSV");
  410. r3.delimiter = e3;
  411. }
  412. const l3 = a4.split(r3.delimiter).filter((e3) => !!e3), d3 = r3.layerDefinition = { name: Ut(i3.url, v) || "csv", drawingInfo: b, geometryType: "esriGeometryPoint", objectIdField: null, fields: [], timeInfo: n3.timeInfo, extent: { xmin: Number.POSITIVE_INFINITY, ymin: Number.POSITIVE_INFINITY, xmax: Number.NEGATIVE_INFINITY, ymax: Number.NEGATIVE_INFINITY, spatialReference: n3.spatialReference || { wkid: 102100 } } };
  413. if (!n3.latitudeField || !n3.longitudeField) {
  414. const e3 = r2(l3);
  415. if (!n3.longitudeField && !e3.longitudeFieldName || !n3.latitudeField && !e3.latitudeFieldName)
  416. throw new s2("csv-layer:location-fields-not-found", "Unable to identify latitude and longitude fields from the CSV file");
  417. r3.locationInfo = { longitudeFieldName: n3.longitudeField || e3.longitudeFieldName, latitudeFieldName: n3.latitudeField || e3.latitudeFieldName };
  418. }
  419. const m = n2(s6, r3.delimiter, l3, r3.locationInfo);
  420. if (n3.fields && n3.fields.length) {
  421. const e3 = new Map();
  422. for (const t4 of n3.fields)
  423. e3.set(t4.name.toLowerCase(), t4);
  424. for (const t4 of m) {
  425. const i4 = e3.get(t4.name.toLowerCase());
  426. if (i4) {
  427. const e4 = t4.name;
  428. Object.assign(t4, i4), t4.name = e4;
  429. }
  430. }
  431. }
  432. d3.fields = m;
  433. if (!d3.fields.some((e3) => e3.type === "esriFieldTypeOID" && (d3.objectIdField = e3.name, true))) {
  434. const e3 = { name: "__OBJECTID", alias: "__OBJECTID", type: "esriFieldTypeOID", editable: false, nullable: false };
  435. d3.objectIdField = e3.name, d3.fields.unshift(e3);
  436. }
  437. if (d3.timeInfo) {
  438. const e3 = new d(d3.fields), t4 = d3.timeInfo;
  439. if (t4.startTimeField) {
  440. const i4 = e3.get(t4.startTimeField);
  441. i4 ? (t4.startTimeField = i4.name, i4.type = "esriFieldTypeDate") : t4.startTimeField = null;
  442. }
  443. if (t4.endTimeField) {
  444. const i4 = e3.get(t4.endTimeField);
  445. i4 ? (t4.endTimeField = i4.name, i4.type = "esriFieldTypeDate") : t4.endTimeField = null;
  446. }
  447. if (t4.trackIdField) {
  448. const i4 = e3.get(t4.trackIdField);
  449. t4.trackIdField = i4 ? i4.name : null;
  450. }
  451. t4.startTimeField || t4.endTimeField || (d3.timeInfo = null);
  452. }
  453. return r3;
  454. }
  455. export {
  456. k3 as default
  457. };
  458. //# sourceMappingURL=CSVSourceWorker-3RM7DFJI.js.map