@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.26 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{handlesGroup as t}from"../../../../../../core/handleUtils.js";import{getOrCreateMapValue as e}from"../../../../../../core/MapUtils.js";import{isAborted as s,throwIfAborted as o,onAbort as r}from"../../../../../../core/promiseUtils.js";import{ATileLoadStrategy as i}from"./ATileLoadStrategy.js";import{PagedTileSourceChunk as a}from"./chunks/PagedTileSourceChunk.js";import{FeatureSetReaderJSON as n}from"../../support/FeatureSetReaderJSON.js";class l{constructor(e,s){this.subscription=e,this._pages=new Set,this._controller=new AbortController,this._done=!1,this._handles=t([r(e.signal,(()=>this._controller.abort())),r(s,(()=>this._controller.abort()))])}destroy(){this._controller.abort(),this._handles.remove()}get pageStart(){let t=-1;for(const e of this._pages.values())t=Math.max(t,e);return t+1}get done(){return this._done}get options(){return{signal:this._controller.signal}}add(t,e){this._pages.add(t),this._done=this._done||e}}class h extends i{constructor(){super(...arguments),this._loadStates=new Map}destroy(){super.destroy();for(const t of this._loadStates.values())t.destroy();this._loadStates.clear()}get about(){return{supportsDisplayFilter:!0,willQueryAllFeatures:!1,willQueryFullResolutionGeometry:!1}}async load(t){const o=e(this._loadStates,t.key.id,(()=>new l(t,this._options)));let r;try{await this._fetchPages(o)}catch(h){r=h}const i=new a(n.empty(this._metadata),null,t.tile,-1,!0);if(s(o.options)||this._addChunk(i),r)throw r}unload(t){super.unload(t),this._loadStates.get(t.key.id)?.destroy(),this._loadStates.delete(t.key.id)}async _fetchPages(t){const e=4,s=20;let r=0,i=t.pageStart,a=1;for(;r<s&&!t.done;){const s=[];for(let e=0;e<a;e++)s.push(this._fetchChunk(t,i++));const n=await Promise.all(s);for(const e of n)(0!==e.size()||e.first)&&(t.add(e.page,!e.reader.exceededTransferLimit),o(t.options),this._addChunk(e));r++,a=Math.min(a+1,e)}}async _fetchChunk(t,e){const s=t.subscription.tile,o=this._queryInfo.createPagedTileQuery(s,e),r=await this._fetch(o,t.options,{chunkId:`${s.id}-${e}`});return new a(r,o.inner.toJSON(),s,e,!1)}}export{h as PagedTileLoadStrategy};