chunk-3KO6RYS2.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import {
  2. c
  3. } from "./chunk-BA3WIOU6.js";
  4. import {
  5. o
  6. } from "./chunk-SOSOZIX6.js";
  7. import {
  8. x
  9. } from "./chunk-K6QDYFZU.js";
  10. import {
  11. v
  12. } from "./chunk-ZHRAUKVQ.js";
  13. import {
  14. n as n2
  15. } from "./chunk-Z4JTBD7M.js";
  16. import {
  17. U as U2
  18. } from "./chunk-5DMBXPN2.js";
  19. import {
  20. Bt
  21. } from "./chunk-VEGAOVMY.js";
  22. import {
  23. k2 as k
  24. } from "./chunk-QCKFNSN2.js";
  25. import {
  26. e,
  27. n5 as n,
  28. y3 as y
  29. } from "./chunk-6SOHRC7T.js";
  30. import {
  31. D,
  32. U
  33. } from "./chunk-V6P2MAQQ.js";
  34. import {
  35. s2 as s,
  36. s3 as s2
  37. } from "./chunk-E5O6P5I2.js";
  38. import {
  39. i,
  40. q,
  41. r,
  42. t
  43. } from "./chunk-YXWMMD76.js";
  44. // node_modules/@arcgis/core/layers/support/StreamConnection.js
  45. var c2 = class extends n2.EventedAccessor {
  46. get connectionError() {
  47. return this.errorString ? new s2("stream-connection", this.errorString) : null;
  48. }
  49. onFeature(r2) {
  50. this.emit("data-received", r2);
  51. }
  52. };
  53. e([y({ readOnly: true })], c2.prototype, "connectionError", null), c2 = e([n("esri.layers.support.StreamConnection")], c2);
  54. var n3 = c2;
  55. // node_modules/@arcgis/core/layers/graphics/sources/connections/WebSocketConnection.js
  56. var p;
  57. !function(e2) {
  58. e2[e2.CONNECTING = 0] = "CONNECTING", e2[e2.OPEN = 1] = "OPEN", e2[e2.CLOSING = 2] = "CLOSING", e2[e2.CLOSED = 3] = "CLOSED";
  59. }(p || (p = {}));
  60. var u = class extends n3 {
  61. constructor(e2) {
  62. super(), this.errorString = null;
  63. const { geometryType: t3, spatialReference: o2, sourceSpatialReference: s3 } = e2;
  64. this._config = e2, this._featureZScaler = o(t3, s3, o2), this._open();
  65. }
  66. async _open() {
  67. await this._tryCreateWebSocket(), this.destroyed || await this._handshake();
  68. }
  69. destroy() {
  70. r(this._websocket) && (this._websocket.onopen = null, this._websocket.onclose = null, this._websocket.onerror = null, this._websocket.onmessage = null, this._websocket.close()), this._websocket = null;
  71. }
  72. get connectionStatus() {
  73. if (t(this._websocket))
  74. return "disconnected";
  75. switch (this._websocket.readyState) {
  76. case p.CONNECTING:
  77. case p.OPEN:
  78. return "connected";
  79. case p.CLOSING:
  80. case p.CLOSED:
  81. return "disconnected";
  82. }
  83. }
  84. async _tryCreateWebSocket(e2 = this._config.source.path, s3 = 1e3, r2 = 0) {
  85. try {
  86. if (this.destroyed)
  87. return;
  88. const t3 = Bt(e2, this._config.customParameters);
  89. this._websocket = await this._createWebSocket(t3), this.notifyChange("connectionStatus");
  90. } catch (c3) {
  91. const i2 = s3 / 1e3;
  92. return this._config.maxReconnectionAttempts && r2 >= this._config.maxReconnectionAttempts ? (s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Exceeded maxReconnectionAttempts attempts. No further attempts will be made")), void this.destroy()) : (s.getLogger(this.declaredClass).error(new s2("websocket-connection", `Failed to connect. Attempting to reconnect in ${i2}s`, c3)), await U(s3), this._tryCreateWebSocket(e2, Math.min(1.5 * s3, 1e3 * this._config.maxReconnectionInterval), r2 + 1));
  93. }
  94. }
  95. _createWebSocket(e2) {
  96. return new Promise((t3, o2) => {
  97. const s3 = new WebSocket(e2);
  98. s3.onopen = () => {
  99. if (s3.onopen = null, this.destroyed)
  100. return s3.onclose = null, void s3.close();
  101. s3.onclose = (e3) => this._onClose(e3), s3.onerror = (e3) => this._onError(e3), s3.onmessage = (e3) => this._onMessage(e3), t3(s3);
  102. }, s3.onclose = (e3) => {
  103. s3.onopen = s3.onclose = null, o2(e3);
  104. };
  105. });
  106. }
  107. async _handshake(e2 = 1e4) {
  108. const s3 = this._websocket;
  109. if (t(s3))
  110. return;
  111. const n4 = D(), i2 = s3.onmessage, { filter: a, outFields: l, spatialReference: d } = this._config;
  112. return n4.timeout(e2), s3.onmessage = (e3) => {
  113. var _a;
  114. let r2 = null;
  115. try {
  116. r2 = JSON.parse(e3.data);
  117. } catch (c3) {
  118. }
  119. r2 && "object" == typeof r2 || (s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Protocol violation. Handshake failed - malformed message", e3.data)), n4.reject(), this.destroy()), ((_a = r2.spatialReference) == null ? void 0 : _a.wkid) !== (d == null ? void 0 : d.wkid) && (s.getLogger(this.declaredClass).error(new s2("websocket-connection", `Protocol violation. Handshake failed - expected wkid of ${d.wkid}`, e3.data)), n4.reject(), this.destroy()), "json" !== r2.format && (s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Protocol violation. Handshake failed - format is not set", e3.data)), n4.reject(), this.destroy()), a && r2.filter !== a && s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Tried to set filter, but server doesn't support it")), l && r2.outFields !== l && s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Tried to set outFields, but server doesn't support it")), s3.onmessage = i2, n4.resolve();
  120. }, s3.send(JSON.stringify({ filter: a, outFields: l, format: "json", spatialReference: { wkid: d.wkid } })), n4.promise;
  121. }
  122. _onMessage(e2) {
  123. try {
  124. const o2 = JSON.parse(e2.data);
  125. if ("featureResult" !== o2.type)
  126. throw new s2("websocket-connection", "Protocol violation - Expected to find message of type 'featureResult'", o2);
  127. for (const e3 of o2.features)
  128. r(this._featureZScaler) && this._featureZScaler(e3.geometry), this.onFeature(e3);
  129. } catch (r2) {
  130. return s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Failed to parse message", r2)), void this.destroy();
  131. }
  132. }
  133. _onError(e2) {
  134. const t3 = "Encountered an error over WebSocket connection";
  135. this._set("errorString", t3), s.getLogger(this.declaredClass).error("websocket-connection", t3);
  136. }
  137. _onClose(e2) {
  138. this._websocket = null, this.notifyChange("connectionStatus"), 1e3 !== e2.code && s.getLogger(this.declaredClass).error("websocket-connection", `WebSocket closed unexpectedly with error code ${e2.code}`), this.destroyed || this._open();
  139. }
  140. };
  141. e([y()], u.prototype, "connectionStatus", null), e([y()], u.prototype, "errorString", void 0), u = e([n("esri.layers.graphics.sources.connections.WebSocketConnection")], u);
  142. // node_modules/@arcgis/core/layers/graphics/sources/connections/GeoEventConnection.js
  143. var m = 1e4;
  144. var p2 = { maxQueryDepth: 5, maxRecordCountFactor: 3 };
  145. var _ = class extends u {
  146. constructor(e2) {
  147. super({ ...p2, ...e2 });
  148. }
  149. async _open() {
  150. const e2 = await this._fetchServiceDefinition(this._config.source);
  151. e2.timeInfo.trackIdField || s.getLogger(this.declaredClass).warn("GeoEvent service was configured without a TrackIdField. This may result in certain functionality being disabled. The purgeOptions.maxObservations property will have no effect.");
  152. const t3 = this._fetchWebSocketUrl(e2.streamUrls, this._config.spatialReference);
  153. this._buddyServicesQuery || (this._buddyServicesQuery = this._queryBuddyServices()), await this._buddyServicesQuery, await this._tryCreateWebSocket(t3);
  154. const { filter: r2, outFields: o2 } = this._config;
  155. this.destroyed || this._setFilter(r2, o2);
  156. }
  157. _onMessage(e2) {
  158. let t3;
  159. try {
  160. t3 = this._enrich(JSON.parse(e2.data)), r(this._featureZScaler) && this._featureZScaler(t3.geometry);
  161. } catch (i2) {
  162. return void s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Failed to parse message", i2));
  163. }
  164. this.onFeature(t3);
  165. }
  166. async _fetchServiceDefinition(e2) {
  167. const r2 = { f: "json", ...this._config.customParameters }, s3 = U2(e2.path, { query: r2, responseType: "json" }), o2 = (await s3).data;
  168. return this._serviceDefinition = o2, o2;
  169. }
  170. _fetchWebSocketUrl(e2, t3) {
  171. const r2 = e2[0], { urls: s3, token: o2 } = r2, i2 = this._inferWebSocketBaseUrl(s3);
  172. return Bt(`${i2}/subscribe`, { outSR: "" + t3.wkid, token: o2 });
  173. }
  174. _inferWebSocketBaseUrl(e2) {
  175. if (1 === e2.length)
  176. return e2[0];
  177. for (const t3 of e2)
  178. if (t3.includes("wss"))
  179. return t3;
  180. return s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Unable to infer WebSocket url", e2)), null;
  181. }
  182. async _setFilter(e2, t3) {
  183. const o2 = this._websocket;
  184. if (t(o2) || t(e2) && t(t3))
  185. return;
  186. const n4 = JSON.stringify({ filter: this._serializeFilter(e2, t3) });
  187. let a = false;
  188. const u2 = D(), d = () => {
  189. a || (this.destroyed || this._websocket !== o2 || s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Server timed out when setting filter")), u2.reject());
  190. }, l = (e3) => {
  191. const t4 = JSON.parse(e3.data);
  192. t4.filter && (t4.error && (s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Failed to set service filter", t4.error)), this._set("errorString", `Could not set service filter - ${t4.error}`), u2.reject(t4.error)), o2.onmessage = this._onMessage.bind(this), a = true, u2.resolve());
  193. };
  194. return o2.onmessage = l, o2.send(n4), setTimeout(d, m), u2.promise;
  195. }
  196. _serializeFilter(e2, t3) {
  197. const n4 = {};
  198. if (t(e2) && t(t3))
  199. return n4;
  200. if (r(e2) && e2.geometry)
  201. try {
  202. const t4 = v(e2.geometry);
  203. if ("extent" !== t4.type)
  204. throw new s2(`Expected extent but found type ${t4.type}`);
  205. n4.geometry = JSON.stringify(t4.shiftCentralMeridian());
  206. } catch (a) {
  207. s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Encountered an error when setting connection geometryDefinition", a));
  208. }
  209. return r(e2) && e2.where && "1 = 1" !== e2.where && (n4.where = e2.where), r(t3) && (n4.outFields = t3.join(",")), n4;
  210. }
  211. _enrich(e2) {
  212. if (!this._relatedFeatures)
  213. return e2;
  214. const t3 = this._serviceDefinition.relatedFeatures.joinField, o2 = e2.attributes[t3];
  215. if (!this._relatedFeatures.has(o2))
  216. return s.getLogger(this.declaredClass).warn("geoevent-connection", "Feature join failed. Is the join field configured correctly?", e2), e2;
  217. const { attributes: i2, geometry: n4 } = this._relatedFeatures.get(o2);
  218. for (const r2 in i2)
  219. e2.attributes[r2] = i2[r2];
  220. return n4 && (e2.geometry = n4), e2.geometry || e2.centroid || s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Found malformed feature - no geometry found", e2)), e2;
  221. }
  222. async _queryBuddyServices() {
  223. try {
  224. const { relatedFeatures: e2, keepLatestArchive: t3 } = this._serviceDefinition, r2 = this._queryRelatedFeatures(e2), s3 = this._queryArchive(t3);
  225. await r2;
  226. const o2 = await s3;
  227. if (!o2)
  228. return;
  229. for (const i2 of o2.features)
  230. this.onFeature(this._enrich(i2));
  231. } catch (e2) {
  232. s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Encountered an error when querying buddy services", { error: e2 }));
  233. }
  234. }
  235. async _queryRelatedFeatures(e2) {
  236. if (!e2)
  237. return;
  238. const t3 = await this._queryBuddy(e2.featuresUrl);
  239. this._addRelatedFeatures(t3);
  240. }
  241. async _queryArchive(e2) {
  242. if (e2)
  243. return this._queryBuddy(e2.featuresUrl);
  244. }
  245. async _queryBuddy(e2) {
  246. const t3 = new (await import("./FeatureLayer-PKSF7I4I.js")).default({ url: e2 }), { capabilities: r2 } = await t3.load(), s3 = r2.query.supportsMaxRecordCountFactor, o2 = r2.query.supportsPagination, i2 = r2.query.supportsCentroid, c3 = this._config.maxRecordCountFactor, u2 = t3.capabilities.query.maxRecordCount, d = s3 ? u2 * c3 : u2, l = new x();
  247. if (l.outFields = i(this._config.outFields, ["*"]), l.where = i(q(this._config.filter, "where"), "1=1"), l.returnGeometry = true, l.returnExceededLimitFeatures = true, l.outSpatialReference = k.fromJSON(this._config.spatialReference), i2 && (l.returnCentroid = true), s3 && (l.maxRecordCountFactor = c3), o2)
  248. return l.num = d, t3.destroy(), this._queryPages(e2, l);
  249. const g = await c(e2, l, this._config.sourceSpatialReference);
  250. return t3.destroy(), g.data;
  251. }
  252. async _queryPages(e2, t3, r2 = [], s3 = 0) {
  253. t3.start = r(t3.num) ? s3 * t3.num : null;
  254. const { data: i2 } = await c(e2, t3, this._config.sourceSpatialReference);
  255. return i2.exceededTransferLimit && s3 < this._config.maxQueryDepth ? (i2.features.forEach((e3) => r2.push(e3)), this._queryPages(e2, t3, r2, s3 + 1)) : (r2.forEach((e3) => i2.features.push(e3)), i2);
  256. }
  257. _addRelatedFeatures(e2) {
  258. const t3 = /* @__PURE__ */ new Map(), r2 = e2.features, s3 = this._serviceDefinition.relatedFeatures.joinField;
  259. for (const o2 of r2) {
  260. const e3 = o2.attributes[s3];
  261. t3.set(e3, o2);
  262. }
  263. this._relatedFeatures = t3;
  264. }
  265. };
  266. _ = e([n("esri.layers.graphics.sources.connections.GeoEventConnection")], _);
  267. var w = _;
  268. // node_modules/@arcgis/core/layers/graphics/sources/connections/createConnection.js
  269. function t2(t3, o2, r2, c3, i2, s3, a, m2) {
  270. const p3 = 0 === t3.path.indexOf("wss://") || 0 === t3.path.indexOf("ws://"), f = { source: t3, sourceSpatialReference: o2, spatialReference: r2, geometryType: c3, filter: i2, maxReconnectionAttempts: s3, maxReconnectionInterval: a, customParameters: m2 };
  271. return p3 ? new u(f) : new w(f);
  272. }
  273. export {
  274. t2 as t
  275. };
  276. //# sourceMappingURL=chunk-3KO6RYS2.js.map