ElevationQuery-BZTDAKT4.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. import {
  2. _n,
  3. rn
  4. } from "./chunk-VYQHMPYW.js";
  5. import "./chunk-SOSOZIX6.js";
  6. import {
  7. t as t2
  8. } from "./chunk-U2WD23Z5.js";
  9. import "./chunk-VGWC3IKZ.js";
  10. import {
  11. R,
  12. c as c2,
  13. f,
  14. u as u2,
  15. w as w3
  16. } from "./chunk-SWMSD4RP.js";
  17. import {
  18. $
  19. } from "./chunk-UKEN2UNL.js";
  20. import {
  21. b
  22. } from "./chunk-PIFOHNWC.js";
  23. import "./chunk-ZLNEXZAN.js";
  24. import "./chunk-RYY6632W.js";
  25. import "./chunk-DW42UVIT.js";
  26. import "./chunk-TJNOJH33.js";
  27. import "./chunk-YAEIHDJH.js";
  28. import "./chunk-OSHI574D.js";
  29. import "./chunk-44GMIOGP.js";
  30. import "./chunk-75U5LM2V.js";
  31. import "./chunk-ZHRAUKVQ.js";
  32. import {
  33. m2 as m,
  34. u
  35. } from "./chunk-RZK6A2GY.js";
  36. import "./chunk-X4LLOW7U.js";
  37. import "./chunk-HZRKBTHJ.js";
  38. import "./chunk-5DMBXPN2.js";
  39. import "./chunk-QANZ6BFY.js";
  40. import "./chunk-VEGAOVMY.js";
  41. import {
  42. M,
  43. w as w2
  44. } from "./chunk-CXCDYJ5R.js";
  45. import "./chunk-GAOW3WRZ.js";
  46. import "./chunk-QCKFNSN2.js";
  47. import "./chunk-6SOHRC7T.js";
  48. import "./chunk-U2XHEJM7.js";
  49. import "./chunk-SQOPWYIT.js";
  50. import "./chunk-6KZ2LTDA.js";
  51. import {
  52. E,
  53. w,
  54. y
  55. } from "./chunk-V6P2MAQQ.js";
  56. import {
  57. s2 as s,
  58. s3 as s2
  59. } from "./chunk-E5O6P5I2.js";
  60. import "./chunk-SPWQ3AWG.js";
  61. import "./chunk-2TIUKVZN.js";
  62. import {
  63. c,
  64. i,
  65. r,
  66. t
  67. } from "./chunk-YXWMMD76.js";
  68. import "./chunk-S5KM4IGW.js";
  69. // node_modules/@arcgis/core/layers/support/ElevationSampler.js
  70. var m2 = s.getLogger("esri.layers.support.ElevationSampler");
  71. var c3 = class {
  72. queryElevation(e2) {
  73. return h(e2.clone(), this);
  74. }
  75. on() {
  76. return g;
  77. }
  78. projectIfRequired(e2, t4) {
  79. return f2(e2, t4);
  80. }
  81. };
  82. var u3 = class extends c3 {
  83. constructor(e2, t4, n) {
  84. super(), this.tile = e2, this.noDataValue = n;
  85. const o = e2.tile.extent;
  86. this.extent = f(o, t4.spatialReference), this.extent.zmin = e2.zmin, this.extent.zmax = e2.zmax, this._aaExtent = o;
  87. const a = $(t4.spatialReference), r2 = t4.lodAt(e2.tile.level).resolution * a;
  88. this.demResolution = { min: r2, max: r2 };
  89. }
  90. get spatialReference() {
  91. return this.extent.spatialReference;
  92. }
  93. contains(e2) {
  94. const n = this.projectIfRequired(e2, this.spatialReference);
  95. return !t(n) && this.containsAt(n.x, n.y);
  96. }
  97. containsAt(e2, t4) {
  98. return w3(this._aaExtent, e2, t4);
  99. }
  100. elevationAt(e2, t4) {
  101. if (!this.containsAt(e2, t4)) {
  102. const n = this.extent, s4 = `${n.xmin}, ${n.ymin}, ${n.xmax}, ${n.ymax}`;
  103. return m2.warn("#elevationAt()", `Point used to sample elevation (${e2}, ${t4}) is outside of the sampler extent (${s4})`), this.noDataValue;
  104. }
  105. return i(this.tile.sample(e2, t4), this.noDataValue);
  106. }
  107. };
  108. var p = class extends c3 {
  109. constructor(e2, t4, n) {
  110. let s4;
  111. super(), "number" == typeof t4 ? (this.noDataValue = t4, s4 = null) : (s4 = t4, this.noDataValue = n), this.samplers = s4 ? e2.map((e3) => new u3(e3, s4, this.noDataValue)) : e2;
  112. const o = this.samplers[0];
  113. if (o) {
  114. this.extent = o.extent.clone();
  115. const { min: e3, max: t5 } = o.demResolution;
  116. this.demResolution = { min: e3, max: t5 };
  117. for (let n2 = 1; n2 < this.samplers.length; n2++) {
  118. const e4 = this.samplers[n2];
  119. this.extent.union(e4.extent), this.demResolution.min = Math.min(this.demResolution.min, e4.demResolution.min), this.demResolution.max = Math.max(this.demResolution.max, e4.demResolution.max);
  120. }
  121. } else
  122. this.extent = f(u2(), s4.spatialReference), this.demResolution = { min: 0, max: 0 };
  123. }
  124. get spatialReference() {
  125. return this.extent.spatialReference;
  126. }
  127. elevationAt(e2, t4) {
  128. for (const n of this.samplers)
  129. if (n.containsAt(e2, t4))
  130. return n.elevationAt(e2, t4);
  131. return m2.warn("#elevationAt()", `Point used to sample elevation (${e2}, ${t4}) is outside of the sampler`), this.noDataValue;
  132. }
  133. };
  134. function h(e2, t4) {
  135. const n = f2(e2, t4.spatialReference);
  136. if (!n)
  137. return null;
  138. switch (e2.type) {
  139. case "point":
  140. x(e2, n, t4);
  141. break;
  142. case "polyline":
  143. R2(e2, n, t4);
  144. break;
  145. case "multipoint":
  146. d(e2, n, t4);
  147. }
  148. return e2;
  149. }
  150. function f2(e2, n) {
  151. if (t(e2))
  152. return null;
  153. const s4 = e2.spatialReference;
  154. if (s4.equals(n))
  155. return e2;
  156. const i2 = M(e2, n);
  157. return i2 || m2.error(`Cannot project geometry spatial reference (wkid:${s4.wkid}) to elevation sampler spatial reference (wkid:${n.wkid})`), i2;
  158. }
  159. function x(e2, t4, n) {
  160. e2.z = n.elevationAt(t4.x, t4.y);
  161. }
  162. function R2(e2, t4, n) {
  163. y2.spatialReference = t4.spatialReference;
  164. const s4 = e2.hasM && !e2.hasZ;
  165. for (let i2 = 0; i2 < e2.paths.length; i2++) {
  166. const o = e2.paths[i2], a = t4.paths[i2];
  167. for (let e3 = 0; e3 < o.length; e3++) {
  168. const t5 = o[e3], i3 = a[e3];
  169. y2.x = i3[0], y2.y = i3[1], s4 && (t5[3] = t5[2]), t5[2] = n.elevationAt(y2.x, y2.y);
  170. }
  171. }
  172. e2.hasZ = true;
  173. }
  174. function d(e2, t4, n) {
  175. y2.spatialReference = t4.spatialReference;
  176. const s4 = e2.hasM && !e2.hasZ;
  177. for (let i2 = 0; i2 < e2.points.length; i2++) {
  178. const o = e2.points[i2], a = t4.points[i2];
  179. y2.x = a[0], y2.y = a[1], s4 && (o[3] = o[2]), o[2] = n.elevationAt(y2.x, y2.y);
  180. }
  181. e2.hasZ = true;
  182. }
  183. var y2 = new w2();
  184. var g = { remove() {
  185. } };
  186. // node_modules/@arcgis/core/layers/support/ElevationSamplerData.js
  187. var t3 = class {
  188. constructor({ values: t4, width: h2, height: i2, noDataValue: s4 }, a) {
  189. this.pixelData = t4, this.width = h2, this.height = i2, this.safeWidth = 0.99999999 * (h2 - 1), this.noDataValue = s4, this.dx = (h2 - 1) / (a[2] - a[0]), this.dy = (h2 - 1) / (a[3] - a[1]), this.x0 = a[0], this.y1 = a[3];
  190. }
  191. };
  192. // node_modules/@arcgis/core/layers/support/ElevationTile.js
  193. var e = class {
  194. constructor(a, e2 = null) {
  195. if (this.tile = a, this.zmin = 0, this.zmax = 0, r(e2) && r(a)) {
  196. const t4 = a.extent;
  197. this._samplerData = new t3(e2, t4), this.zmin = e2.minValue, this.zmax = e2.maxValue;
  198. }
  199. }
  200. sample(t4, i2) {
  201. if (t(this._samplerData))
  202. return;
  203. const { safeWidth: e2, width: r2, pixelData: o, noDataValue: n, dx: l, dy: m3, y1: h2, x0: f3 } = this._samplerData, p2 = s3(m3 * (h2 - i2), 0, e2), u4 = s3(l * (t4 - f3), 0, e2), c4 = Math.floor(p2), x3 = Math.floor(u4), D = c4 * r2 + x3, d2 = D + r2, z = o[D], y3 = o[d2], V = o[D + 1], _2 = o[d2 + 1];
  204. if (z !== n && y3 !== n && V !== n && _2 !== n) {
  205. const t5 = u4 - x3, a = z + (V - z) * t5;
  206. return a + (y3 + (_2 - y3) * t5 - a) * (p2 - c4);
  207. }
  208. }
  209. };
  210. function s3(t4, a, i2) {
  211. return t4 < a ? a : t4 > i2 ? i2 : t4;
  212. }
  213. // node_modules/@arcgis/core/layers/support/ElevationQuery.js
  214. var g2 = class {
  215. async queryAll(e2, i2, s4) {
  216. if (!(e2 = s4 && s4.ignoreInvisibleLayers ? e2.filter((e3) => e3.visible) : e2.slice()).length)
  217. throw new s2("elevation-query:invalid-layer", "Elevation queries require at least one elevation layer to fetch tiles from");
  218. const n = x2.fromGeometry(i2);
  219. let o = false;
  220. s4 && s4.returnSampleInfo || (o = true);
  221. const l = { ...A, ...s4, returnSampleInfo: true }, a = await this.query(e2[e2.length - 1], n, l), r2 = await this._queryAllContinue(e2, a, l);
  222. return r2.geometry = r2.geometry.export(), o && delete r2.sampleInfo, r2;
  223. }
  224. async query(e2, i2, s4) {
  225. if (!e2)
  226. throw new s2("elevation-query:invalid-layer", "Elevation queries require an elevation layer to fetch tiles from");
  227. if (!i2 || !(i2 instanceof x2) && "point" !== i2.type && "multipoint" !== i2.type && "polyline" !== i2.type)
  228. throw new s2("elevation-query:invalid-geometry", "Only point, polyline and multipoint geometries can be used to query elevation");
  229. const n = { ...A, ...s4 }, o = new R3(e2, i2.spatialReference, n), l = n.signal;
  230. return await e2.load({ signal: l }), await this._createGeometryDescriptor(o, i2, l), await this._selectTiles(o, l), await this._populateElevationTiles(o, l), this._sampleGeometryWithElevation(o), this._createQueryResult(o, l);
  231. }
  232. async createSampler(e2, i2, s4) {
  233. if (!e2)
  234. throw new s2("elevation-query:invalid-layer", "Elevation queries require an elevation layer to fetch tiles from");
  235. if (!i2 || "extent" !== i2.type)
  236. throw new s2("elevation-query:invalid-extent", "Invalid or undefined extent");
  237. const n = { ...A, ...s4 };
  238. return this._createSampler(e2, i2, n);
  239. }
  240. async createSamplerAll(e2, i2, s4) {
  241. if (!(e2 = s4 && s4.ignoreInvisibleLayers ? e2.filter((e3) => e3.visible) : e2.slice()).length)
  242. throw new s2("elevation-query:invalid-layer", "Elevation queries require at least one elevation layer to fetch tiles from");
  243. if (!i2 || "extent" !== i2.type)
  244. throw new s2("elevation-query:invalid-extent", "Invalid or undefined extent");
  245. const n = { ...A, ...s4, returnSampleInfo: true }, o = await this._createSampler(e2[e2.length - 1], i2, n);
  246. return this._createSamplerAllContinue(e2, i2, o, n);
  247. }
  248. async _createSampler(e2, t4, i2, s4) {
  249. const n = i2.signal;
  250. await e2.load({ signal: n });
  251. const o = t4.spatialReference, l = e2.tileInfo.spatialReference;
  252. o.equals(l) || (await _n([{ source: o, dest: l }], { signal: n }), t4 = rn(t4, l));
  253. const a = new q(e2, t4, i2, s4);
  254. return await this._selectTiles(a, n), await this._populateElevationTiles(a, n), new p(a.elevationTiles, a.layer.tileInfo, a.options.noDataValue);
  255. }
  256. async _createSamplerAllContinue(e2, t4, i2, s4) {
  257. if (e2.pop(), !e2.length)
  258. return i2;
  259. const n = i2.samplers.map((e3) => c2(e3.extent)), o = await this._createSampler(e2[e2.length - 1], t4, s4, n);
  260. if (0 === o.samplers.length)
  261. return i2;
  262. const l = i2.samplers.concat(o.samplers), a = new p(l, s4.noDataValue);
  263. return this._createSamplerAllContinue(e2, t4, a, s4);
  264. }
  265. async _queryAllContinue(e2, t4, s4) {
  266. const n = e2.pop(), o = t4.geometry.coordinates, l = t4.sampleInfo;
  267. c(l);
  268. const a = [], r2 = [];
  269. for (let i2 = 0; i2 < o.length; i2++) {
  270. const t5 = l[i2];
  271. t5.demResolution >= 0 ? t5.source || (t5.source = n) : e2.length && (a.push(o[i2]), r2.push(i2));
  272. }
  273. if (!e2.length || 0 === a.length)
  274. return t4;
  275. const c4 = t4.geometry.clone(a), u4 = await this.query(e2[e2.length - 1], c4, s4), h2 = u4.sampleInfo;
  276. if (!h2)
  277. throw new Error("no sampleInfo");
  278. return r2.forEach((e3, t5) => {
  279. o[e3].z = u4.geometry.coordinates[t5].z, l[e3].demResolution = h2[t5].demResolution;
  280. }), this._queryAllContinue(e2, t4, s4);
  281. }
  282. async _createQueryResult(e2, t4) {
  283. const s4 = await e2.geometry.project(e2.outSpatialReference, t4);
  284. c(s4);
  285. const n = { geometry: s4.export(), noDataValue: e2.options.noDataValue };
  286. return e2.options.returnSampleInfo && (n.sampleInfo = this._extractSampleInfo(e2)), e2.geometry.coordinates.forEach((e3) => {
  287. e3.tile = null, e3.elevationTile = null;
  288. }), n;
  289. }
  290. async _createGeometryDescriptor(e2, i2, s4) {
  291. let n;
  292. const o = e2.layer.tileInfo.spatialReference;
  293. if (i2 instanceof x2 ? n = await i2.project(o, s4) : (await _n([{ source: i2.spatialReference, dest: o }], { signal: s4 }), n = rn(i2, o)), !n)
  294. throw new s2("elevation-query:spatial-reference-mismatch", `Cannot query elevation in '${i2.spatialReference.wkid}' on an elevation service in '${o.wkid}'`);
  295. e2.geometry = x2.fromGeometry(n);
  296. }
  297. async _selectTiles(e2, i2) {
  298. const s4 = e2.options.demResolution;
  299. if ("geometry" === e2.type && this._preselectOutsideLayerExtent(e2), "number" == typeof s4)
  300. this._selectTilesClosestResolution(e2);
  301. else if ("finest-contiguous" === s4)
  302. await this._selectTilesFinestContiguous(e2, i2);
  303. else {
  304. if ("auto" !== s4)
  305. throw new s2("elevation-query:invalid-dem-resolution", `Invalid dem resolution value '${s4}', expected a number, "finest-contiguous" or "auto"`);
  306. await this._selectTilesAuto(e2, i2);
  307. }
  308. }
  309. _preselectOutsideLayerExtent(e2) {
  310. if (t(e2.layer.fullExtent))
  311. return;
  312. const t4 = new e(null);
  313. t4.sample = () => e2.options.noDataValue, e2.outsideExtentTile = t4;
  314. const i2 = e2.layer.fullExtent;
  315. e2.geometry.coordinates.forEach((e3) => {
  316. const s4 = e3.x, n = e3.y;
  317. (s4 < i2.xmin || s4 > i2.xmax || n < i2.ymin || n > i2.ymax) && (e3.elevationTile = t4);
  318. });
  319. }
  320. _selectTilesClosestResolution(e2) {
  321. const t4 = e2.layer.tileInfo, i2 = this._findNearestDemResolutionLODIndex(t4, e2.options.demResolution);
  322. e2.selectTilesAtLOD(i2);
  323. }
  324. _findNearestDemResolutionLODIndex(e2, t4) {
  325. const i2 = t4 / $(e2.spatialReference);
  326. let s4 = e2.lods[0], n = 0;
  327. for (let o = 1; o < e2.lods.length; o++) {
  328. const t5 = e2.lods[o];
  329. Math.abs(t5.resolution - i2) < Math.abs(s4.resolution - i2) && (s4 = t5, n = o);
  330. }
  331. return n;
  332. }
  333. async _selectTilesFinestContiguous(e2, t4) {
  334. const i2 = I(e2.layer.tileInfo, e2.options.minDemResolution);
  335. await this._selectTilesFinestContiguousAt(e2, i2, t4);
  336. }
  337. async _selectTilesFinestContiguousAt(e2, i2, s4) {
  338. const n = e2.layer;
  339. if (e2.selectTilesAtLOD(i2), i2 < 0)
  340. return;
  341. const a = n.tilemapCache, r2 = e2.getTilesToFetch();
  342. try {
  343. if (a)
  344. await y(Promise.all(r2.map((e3) => a.fetchAvailability(e3.level, e3.row, e3.col, { signal: s4 }))), s4);
  345. else if (await this._populateElevationTiles(e2, s4), !e2.allElevationTilesFetched())
  346. throw e2.clearElevationTiles(), new s2("elevation-query:has-unavailable-tiles");
  347. } catch (c4) {
  348. w(c4), await this._selectTilesFinestContiguousAt(e2, i2 - 1, s4);
  349. }
  350. }
  351. async _populateElevationTiles(e2, t4) {
  352. const i2 = e2.getTilesToFetch(), s4 = {}, l = e2.options.cache, r2 = e2.options.noDataValue, c4 = i2.map(async (i3) => {
  353. if (null == i3.id)
  354. return;
  355. const o = `${e2.layer.uid}:${i3.id}:${r2}`, a = r(l) ? l.get(o) : null, c5 = r(a) ? a : await e2.layer.fetchTile(i3.level, i3.row, i3.col, { noDataValue: r2, signal: t4 });
  356. r(l) && l.put(o, c5), s4[i3.id] = new e(i3, c5);
  357. });
  358. await y(E(c4), t4), e2.populateElevationTiles(s4);
  359. }
  360. async _selectTilesAuto(t4, i2) {
  361. this._selectTilesAutoFinest(t4), this._reduceTilesForMaximumRequests(t4);
  362. const s4 = t4.layer.tilemapCache;
  363. if (!s4)
  364. return this._selectTilesAutoPrefetchUpsample(t4, i2);
  365. const n = t4.getTilesToFetch(), a = {}, r2 = n.map(async (t5) => {
  366. const n2 = new t2(null, 0, 0, 0, u2()), o = await b(s4.fetchAvailabilityUpsample(t5.level, t5.row, t5.col, n2, { signal: i2 }));
  367. false !== o.ok ? null != t5.id && (a[t5.id] = n2) : w(o.error);
  368. });
  369. await y(Promise.all(r2), i2), t4.remapTiles(a);
  370. }
  371. _reduceTilesForMaximumRequests(e2) {
  372. const t4 = e2.layer.tileInfo;
  373. let i2 = 0;
  374. const s4 = {}, n = (e3) => {
  375. null != e3.id && (e3.id in s4 ? s4[e3.id]++ : (s4[e3.id] = 1, i2++));
  376. }, o = (e3) => {
  377. if (null == e3.id)
  378. return;
  379. const t5 = s4[e3.id];
  380. 1 === t5 ? (delete s4[e3.id], i2--) : s4[e3.id] = t5 - 1;
  381. };
  382. e2.forEachTileToFetch(n, o);
  383. let l = true;
  384. for (; l && (l = false, e2.forEachTileToFetch((s5) => {
  385. i2 <= e2.options.maximumAutoTileRequests || (o(s5), t4.upsampleTile(s5) && (l = true), n(s5));
  386. }, o), l); )
  387. ;
  388. }
  389. _selectTilesAutoFinest(e2) {
  390. const t4 = I(e2.layer.tileInfo, e2.options.minDemResolution);
  391. e2.selectTilesAtLOD(t4, e2.options.maximumAutoTileRequests);
  392. }
  393. async _selectTilesAutoPrefetchUpsample(e2, t4) {
  394. const i2 = e2.layer.tileInfo;
  395. await this._populateElevationTiles(e2, t4);
  396. let s4 = false;
  397. e2.forEachTileToFetch((e3, t5) => {
  398. i2.upsampleTile(e3) ? s4 = true : t5();
  399. }), s4 && await this._selectTilesAutoPrefetchUpsample(e2, t4);
  400. }
  401. _sampleGeometryWithElevation(e2) {
  402. e2.geometry.coordinates.forEach((t4) => {
  403. const i2 = t4.elevationTile;
  404. let s4 = e2.options.noDataValue;
  405. if (i2) {
  406. const e3 = i2.sample(t4.x, t4.y);
  407. r(e3) ? s4 = e3 : t4.elevationTile = null;
  408. }
  409. t4.z = s4;
  410. });
  411. }
  412. _extractSampleInfo(e2) {
  413. const t4 = e2.layer.tileInfo, i2 = $(t4.spatialReference);
  414. return e2.geometry.coordinates.map((s4) => {
  415. let n = -1;
  416. if (s4.elevationTile && s4.elevationTile !== e2.outsideExtentTile) {
  417. n = t4.lodAt(s4.elevationTile.tile.level).resolution * i2;
  418. }
  419. return { demResolution: n };
  420. });
  421. }
  422. };
  423. var x2 = class {
  424. export() {
  425. return this._exporter(this.coordinates, this.spatialReference);
  426. }
  427. clone(e2) {
  428. const t4 = new x2();
  429. return t4.geometry = this.geometry, t4.spatialReference = this.spatialReference, t4.coordinates = e2 || this.coordinates.map((e3) => e3.clone()), t4._exporter = this._exporter, t4;
  430. }
  431. async project(e2, t4) {
  432. if (this.spatialReference.equals(e2))
  433. return this.clone();
  434. await _n([{ source: this.spatialReference, dest: e2 }], { signal: t4 });
  435. const i2 = new u({ spatialReference: this.spatialReference, points: this.coordinates.map((e3) => [e3.x, e3.y]) }), s4 = rn(i2, e2);
  436. if (!s4)
  437. return null;
  438. const n = this.coordinates.map((e3, t5) => {
  439. const i3 = e3.clone(), n2 = s4.points[t5];
  440. return i3.x = n2[0], i3.y = n2[1], i3;
  441. }), o = this.clone(n);
  442. return o.spatialReference = e2, o;
  443. }
  444. static fromGeometry(e2) {
  445. const t4 = new x2();
  446. if (t4.geometry = e2, t4.spatialReference = e2.spatialReference, e2 instanceof x2)
  447. t4.coordinates = e2.coordinates.map((e3) => e3.clone()), t4._exporter = (t5, i2) => {
  448. const s4 = e2.clone(t5);
  449. return s4.spatialReference = i2, s4;
  450. };
  451. else
  452. switch (e2.type) {
  453. case "point": {
  454. const i2 = e2, { hasZ: s4, hasM: n } = i2;
  455. t4.coordinates = s4 && n ? [new _(i2.x, i2.y, i2.z, i2.m)] : s4 ? [new _(i2.x, i2.y, i2.z)] : n ? [new _(i2.x, i2.y, null, i2.m)] : [new _(i2.x, i2.y)], t4._exporter = (t5, i3) => e2.hasM ? new w2(t5[0].x, t5[0].y, t5[0].z, t5[0].m, i3) : new w2(t5[0].x, t5[0].y, t5[0].z, i3);
  456. break;
  457. }
  458. case "multipoint": {
  459. const i2 = e2, { hasZ: s4, hasM: n } = i2;
  460. t4.coordinates = s4 && n ? i2.points.map((e3) => new _(e3[0], e3[1], e3[2], e3[3])) : s4 ? i2.points.map((e3) => new _(e3[0], e3[1], e3[2])) : n ? i2.points.map((e3) => new _(e3[0], e3[1], null, e3[2])) : i2.points.map((e3) => new _(e3[0], e3[1])), t4._exporter = (t5, i3) => e2.hasM ? new u({ points: t5.map((e3) => [e3.x, e3.y, e3.z, e3.m]), hasZ: true, hasM: true, spatiaReference: i3 }) : new u(t5.map((e3) => [e3.x, e3.y, e3.z]), i3);
  461. break;
  462. }
  463. case "polyline": {
  464. const i2 = e2, s4 = [], n = [], { hasZ: o, hasM: l } = e2;
  465. let a = 0;
  466. for (const e3 of i2.paths)
  467. if (n.push([a, a + e3.length]), a += e3.length, o && l)
  468. for (const t5 of e3)
  469. s4.push(new _(t5[0], t5[1], t5[2], t5[3]));
  470. else if (o)
  471. for (const t5 of e3)
  472. s4.push(new _(t5[0], t5[1], t5[2]));
  473. else if (l)
  474. for (const t5 of e3)
  475. s4.push(new _(t5[0], t5[1], null, t5[2]));
  476. else
  477. for (const t5 of e3)
  478. s4.push(new _(t5[0], t5[1]));
  479. t4.coordinates = s4, t4._exporter = (t5, i3) => {
  480. const s5 = e2.hasM ? t5.map((e3) => [e3.x, e3.y, e3.z, e3.m]) : t5.map((e3) => [e3.x, e3.y, e3.z]), o2 = n.map((e3) => s5.slice(e3[0], e3[1]));
  481. return new m({ paths: o2, hasM: e2.hasM, hasZ: true, spatialReference: i3 });
  482. };
  483. break;
  484. }
  485. }
  486. return t4;
  487. }
  488. };
  489. var _ = class {
  490. constructor(e2, t4, i2 = null, s4 = null, n = null, o = null) {
  491. this.x = e2, this.y = t4, this.z = i2, this.m = s4, this.tile = n, this.elevationTile = o;
  492. }
  493. clone() {
  494. return new _(this.x, this.y, this.z, this.m);
  495. }
  496. };
  497. var E2 = class {
  498. constructor(e2, t4) {
  499. this.layer = e2, this.options = t4;
  500. }
  501. };
  502. var R3 = class extends E2 {
  503. constructor(e2, t4, i2) {
  504. super(e2, i2), this.outSpatialReference = t4, this.type = "geometry";
  505. }
  506. selectTilesAtLOD(e2) {
  507. if (e2 < 0)
  508. this.geometry.coordinates.forEach((e3) => {
  509. e3.tile = null;
  510. });
  511. else {
  512. const t4 = this.layer.tileInfo, i2 = t4.lods[e2].level;
  513. this.geometry.coordinates.forEach((e3) => {
  514. e3.tile = t4.tileAt(i2, e3.x, e3.y);
  515. });
  516. }
  517. }
  518. allElevationTilesFetched() {
  519. return !this.geometry.coordinates.some((e2) => !e2.elevationTile);
  520. }
  521. clearElevationTiles() {
  522. for (const e2 of this.geometry.coordinates)
  523. e2.elevationTile !== this.outsideExtentTile && (e2.elevationTile = null);
  524. }
  525. populateElevationTiles(e2) {
  526. var _a;
  527. for (const t4 of this.geometry.coordinates)
  528. !t4.elevationTile && ((_a = t4.tile) == null ? void 0 : _a.id) && (t4.elevationTile = e2[t4.tile.id]);
  529. }
  530. remapTiles(e2) {
  531. var _a;
  532. for (const t4 of this.geometry.coordinates) {
  533. const i2 = (_a = t4.tile) == null ? void 0 : _a.id;
  534. t4.tile = i2 ? e2[i2] : null;
  535. }
  536. }
  537. getTilesToFetch() {
  538. var _a;
  539. const e2 = {}, t4 = [];
  540. for (const i2 of this.geometry.coordinates) {
  541. const s4 = i2.tile;
  542. if (!s4)
  543. continue;
  544. const n = (_a = i2.tile) == null ? void 0 : _a.id;
  545. i2.elevationTile || !n || e2[n] || (e2[n] = s4, t4.push(s4));
  546. }
  547. return t4;
  548. }
  549. forEachTileToFetch(e2) {
  550. for (const t4 of this.geometry.coordinates)
  551. t4.tile && !t4.elevationTile && e2(t4.tile, () => {
  552. t4.tile = null;
  553. });
  554. }
  555. };
  556. var q = class extends E2 {
  557. constructor(e2, t4, i2, s4) {
  558. super(e2, i2), this.type = "extent", this.elevationTiles = [], this._candidateTiles = [], this._fetchedCandidates = /* @__PURE__ */ new Set(), this.extent = t4.intersection(e2.fullExtent), this.maskExtents = s4;
  559. }
  560. selectTilesAtLOD(e2, t4) {
  561. const i2 = this._maximumLodForRequests(t4), s4 = Math.min(i2, e2);
  562. s4 < 0 ? this._candidateTiles.length = 0 : this._selectCandidateTilesCoveringExtentAt(s4);
  563. }
  564. _maximumLodForRequests(e2) {
  565. const t4 = this.layer.tileInfo;
  566. if (!e2)
  567. return t4.lods.length - 1;
  568. const i2 = this.extent;
  569. if (t(i2))
  570. return -1;
  571. for (let s4 = t4.lods.length - 1; s4 >= 0; s4--) {
  572. const n = t4.lods[s4], o = n.resolution * t4.size[0], l = n.resolution * t4.size[1];
  573. if (Math.ceil(i2.width / o) * Math.ceil(i2.height / l) <= e2)
  574. return s4;
  575. }
  576. return -1;
  577. }
  578. allElevationTilesFetched() {
  579. return this._candidateTiles.length === this.elevationTiles.length;
  580. }
  581. clearElevationTiles() {
  582. this.elevationTiles.length = 0, this._fetchedCandidates.clear();
  583. }
  584. populateElevationTiles(e2) {
  585. for (const t4 of this._candidateTiles) {
  586. const i2 = t4.id && e2[t4.id];
  587. i2 && (this._fetchedCandidates.add(t4), this.elevationTiles.push(i2));
  588. }
  589. }
  590. remapTiles(e2) {
  591. this._candidateTiles = this._uniqueNonOverlappingTiles(this._candidateTiles.map((t4) => e2[t4.id]));
  592. }
  593. getTilesToFetch() {
  594. return this._candidateTiles;
  595. }
  596. forEachTileToFetch(e2, t4) {
  597. const i2 = this._candidateTiles;
  598. this._candidateTiles = [], i2.forEach((i3) => {
  599. if (this._fetchedCandidates.has(i3))
  600. return void (t4 && t4(i3));
  601. let s4 = false;
  602. e2(i3, () => s4 = true), s4 ? t4 && t4(i3) : this._candidateTiles.push(i3);
  603. }), this._candidateTiles = this._uniqueNonOverlappingTiles(this._candidateTiles, t4);
  604. }
  605. _uniqueNonOverlappingTiles(e2, t4) {
  606. const i2 = {}, s4 = [];
  607. for (const o of e2) {
  608. const e3 = o.id;
  609. e3 && !i2[e3] ? (i2[e3] = o, s4.push(o)) : t4 && t4(o);
  610. }
  611. const n = s4.sort((e3, t5) => e3.level - t5.level);
  612. return n.filter((e3, i3) => {
  613. for (let s5 = 0; s5 < i3; s5++) {
  614. const i4 = n[s5].extent;
  615. if (i4 && e3.extent && R(i4, e3.extent))
  616. return t4 && t4(e3), false;
  617. }
  618. return true;
  619. });
  620. }
  621. _selectCandidateTilesCoveringExtentAt(e2) {
  622. this._candidateTiles.length = 0;
  623. const t4 = this.extent;
  624. if (t(t4))
  625. return;
  626. const i2 = this.layer.tileInfo, n = i2.lods[e2], o = i2.tileAt(n.level, t4.xmin, t4.ymin), l = o.extent;
  627. if (t(l))
  628. return;
  629. const a = n.resolution * i2.size[0], r2 = n.resolution * i2.size[1], c4 = Math.ceil((t4.xmax - l[0]) / a), u4 = Math.ceil((t4.ymax - l[1]) / r2);
  630. for (let s4 = 0; s4 < u4; s4++)
  631. for (let e3 = 0; e3 < c4; e3++) {
  632. const t5 = new t2(null, o.level, o.row - s4, o.col + e3);
  633. i2.updateTileInfo(t5), this._tileIsMasked(t5) || this._candidateTiles.push(t5);
  634. }
  635. }
  636. _tileIsMasked(e2) {
  637. return !!this.maskExtents && this.maskExtents.some((t4) => e2.extent && R(t4, e2.extent));
  638. }
  639. };
  640. function I(e2, t4 = 0) {
  641. let i2 = e2.lods.length - 1;
  642. if (t4 > 0) {
  643. const s4 = t4 / $(e2.spatialReference), n = e2.lods.findIndex((e3) => e3.resolution < s4);
  644. 0 === n ? i2 = 0 : n > 0 && (i2 = n - 1);
  645. }
  646. return i2;
  647. }
  648. var A = { maximumAutoTileRequests: 20, noDataValue: 0, returnSampleInfo: false, demResolution: "auto", minDemResolution: 0 };
  649. export {
  650. g2 as ElevationQuery,
  651. x2 as GeometryDescriptor,
  652. I as getFinestLodIndex
  653. };
  654. //# sourceMappingURL=ElevationQuery-BZTDAKT4.js.map