import { l } from "./chunk-DGINNG7Z.js"; import { m as m2 } from "./chunk-E3G7BRZB.js"; import { e, m, n5 as n, y3 as y } from "./chunk-6SOHRC7T.js"; import { s } from "./chunk-YXWMMD76.js"; // node_modules/@arcgis/core/views/2d/tiling/TileQueue.js function u(e2, t) { return e2.length = 0, t.forEach((t2) => e2.push(t2)), e2; } var c = /* @__PURE__ */ new Set(); var a = []; var h = /* @__PURE__ */ new Map(); var l2 = [0, 0]; var p = class extends m { constructor(e2) { super(e2), this._keyToItem = /* @__PURE__ */ new Map(), this.concurrency = 6, this.strategy = "scale-first", this.tileInfoView = null; } initialize() { const { concurrency: e2, process: t, strategy: s2 } = this; this._queue = new l({ concurrency: e2, process: (e3, s3) => { const r = this._keyToItem.get(e3); return t(r, { signal: s3 }); }, peeker: "scale-first" === s2 ? (e3) => this._peekByScaleFirst(e3) : (e3) => this._peekByCenterFirst(e3) }); } destroy() { this.clear(), this._queue = s(this._queue); } get length() { return this._queue ? this._queue.length : 0; } get onGoingCount() { return this._keyToItem.size; } get updating() { return this.length > 0 || this.onGoingCount > 0; } abort(e2) { const t = "string" == typeof e2 ? e2 : e2.id; this._queue.abort(t); } clear() { this._queue.clear(), this._keyToItem.clear(), this.notifyChange("updating"); } has(e2) { return "string" == typeof e2 ? this._keyToItem.has(e2) : this._keyToItem.has(e2.id); } isOngoing(e2) { const t = "string" == typeof e2 ? e2 : e2.id; return this.has(t) && this._queue.isOngoing(t); } pause() { this._queue.pause(); } push(e2) { const t = e2.key.id; if (this._queue.has(t)) return this._queue.get(t); const s2 = this._queue.push(t), r = () => { this._keyToItem.delete(t), this.notifyChange("updating"); }; return this._keyToItem.set(t, e2), s2.then(r, r), this.notifyChange("updating"), s2; } reset() { this._queue.reset(); } resume() { this._queue.resume(); } _peekByScaleFirst(e2) { if (!this.state) return e2.values().next().value; const t = this.tileInfoView; let s2 = Number.NEGATIVE_INFINITY, r = Number.POSITIVE_INFINITY; e2.forEach((e3) => { const t2 = this._keyToItem.get(e3), o2 = this.tileInfoView.getTileScale(t2.key); h.has(o2) || (h.set(o2, []), s2 = Math.max(o2, s2), r = Math.min(o2, r)), h.get(o2).push(t2.key), c.add(o2); }); let o = this.state.scale; h.has(o) || (u(a, c), a.sort((e3, t2) => e3 - t2), o = a.reduce((e3, t2) => Math.abs(t2 - o) < Math.abs(e3 - o) ? t2 : e3, a[0])), o = Math.min(o, s2), o = Math.max(o, r); const i = h.get(o), n2 = t.getClosestInfoForScale(o), l3 = n2.getColumnForX(this.state.center[0]), p2 = n2.getRowForY(this.state.center[1]); return i.sort((e3, t2) => { const s3 = n2.denormalizeCol(e3.col, e3.world), r2 = n2.denormalizeCol(t2.col, t2.world); return Math.sqrt((l3 - s3) * (l3 - s3) + (p2 - e3.row) * (p2 - e3.row)) - Math.sqrt((l3 - r2) * (l3 - r2) + (p2 - t2.row) * (p2 - t2.row)); }), c.clear(), h.clear(), i[0].id; } _peekByCenterFirst(e2) { if (!this.state) return e2.values().next().value; const t = this.tileInfoView, s2 = this.state.center; let r, o = Number.POSITIVE_INFINITY; return e2.forEach((e3) => { const n2 = this._keyToItem.get(e3); t.getTileCoords(l2, n2.key); const u2 = m2(l2, s2); u2 < o && (o = u2, r = n2.key); }), r.id; } }; e([y({ constructOnly: true })], p.prototype, "concurrency", void 0), e([y({ constructOnly: true })], p.prototype, "process", void 0), e([y()], p.prototype, "state", void 0), e([y({ constructOnly: true })], p.prototype, "strategy", void 0), e([y({ constructOnly: true })], p.prototype, "tileInfoView", void 0), e([y({ readOnly: true })], p.prototype, "updating", null), p = e([n("esri.views.2d.tiling.TileQueue")], p); var y2 = p; export { y2 as y }; //# sourceMappingURL=chunk-PQGNKUMB.js.map